87 lines
2.9 KiB
C#
87 lines
2.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BehaviorDesigner.Runtime.Tasks.Unity.UnityGameObject;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater
|
|
{
|
|
public class TestCharacterMove_01 : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private GameObject obj;
|
|
|
|
public float speed = 50.0f;
|
|
protected float force = 0.0f;
|
|
public float force_add = 0.002f;
|
|
|
|
[SerializeField]
|
|
private float rotate_speed = 1.0f;
|
|
|
|
[SerializeField]
|
|
private ParticleSystem Rings;
|
|
|
|
|
|
void Update()
|
|
{
|
|
float rotation_01 = Mathf.Abs(-0.5f + ((obj.transform.eulerAngles.y)/ 180) % 1.0f);
|
|
float rotation_02 = Mathf.Abs(-0.5f + rotation_01);
|
|
float back_check = (obj.transform.eulerAngles.y >= 90.0f && obj.transform.eulerAngles.y <= 270.0f) ? 1.0f : -1.0f;
|
|
float side_check = (obj.transform.eulerAngles.y <= 180.0f)? -1.0f : 1.0f;
|
|
|
|
float time = Time.deltaTime;
|
|
|
|
float move_time = (-speed * time);
|
|
|
|
if (Input.GetKey(KeyCode.UpArrow)|| Input.GetKey(KeyCode.T))
|
|
{
|
|
force += force_add;
|
|
if (force >= 1.0f) force = 1.0f;
|
|
}
|
|
else if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.G))
|
|
{
|
|
if (force > 0.0f)
|
|
{
|
|
force -= force_add;
|
|
if (force <= 0.0f) force = 0.0f;
|
|
}
|
|
else
|
|
{
|
|
force -= force_add/4.0f;
|
|
if (force <= -0.5f) force = -0.5f;
|
|
}
|
|
// transform.Translate(0, 0, speed * time);
|
|
}
|
|
else
|
|
{
|
|
if (force < 0.0f)force += force_add/2.0f;
|
|
else if(force > 0.0f)force -= force_add/2.0f;
|
|
}
|
|
|
|
|
|
transform.Translate((side_check * move_time * rotation_02)*force, 0.0f, (back_check * move_time * rotation_01)*force);
|
|
if (force >= 0.05f && !Rings.isPlaying)
|
|
{
|
|
Rings.Play();
|
|
}
|
|
else if(force < 0.05f && Rings.isPlaying)
|
|
{
|
|
Rings.Stop();
|
|
}
|
|
|
|
if (Input.GetKey(KeyCode.RightArrow)|| Input.GetKey(KeyCode.H))
|
|
{
|
|
obj.transform.Rotate(new Vector3(0.0f, speed * Time.deltaTime * rotate_speed , 0.0f));
|
|
}
|
|
else if (Input.GetKey(KeyCode.LeftArrow)|| Input.GetKey(KeyCode.F))
|
|
{
|
|
obj.transform.Rotate(new Vector3(0.0f, speed * -Time.deltaTime * rotate_speed, 0.0f));
|
|
}
|
|
else
|
|
{
|
|
obj.transform.Rotate(new Vector3(0.0f, 0.0f * Time.deltaTime * rotate_speed, 0.0f));
|
|
}
|
|
|
|
}
|
|
}
|
|
} |