CapersProject/Assets/02.Scripts/BlueWater/Sail/ShipMove.cs

87 lines
2.9 KiB
C#
Raw Normal View History

2025-02-27 04:27:27 +00:00
using System;
2025-02-07 13:15:29 +00:00
using System.Collections;
using System.Collections.Generic;
2025-02-18 06:56:30 +00:00
using BehaviorDesigner.Runtime.Tasks.Unity.UnityGameObject;
2025-02-07 13:15:29 +00:00
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;
2025-02-18 06:56:30 +00:00
2025-02-27 04:27:27 +00:00
[SerializeField]
private ParticleSystem Rings;
2025-02-07 13:15:29 +00:00
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))
2025-02-07 13:15:29 +00:00
{
force += force_add;
if (force >= 1.0f) force = 1.0f;
}
else if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.G))
2025-02-07 13:15:29 +00:00
{
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
2025-02-27 04:27:27 +00:00
{
2025-02-07 13:15:29 +00:00
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);
2025-03-01 09:43:23 +00:00
if (force >= 0.05f && !Rings.isPlaying)
2025-02-27 04:27:27 +00:00
{
2025-03-01 09:43:23 +00:00
Rings.Play();
2025-02-27 04:27:27 +00:00
}
2025-03-01 09:43:23 +00:00
else if(force < 0.05f && Rings.isPlaying)
2025-02-27 04:27:27 +00:00
{
2025-03-01 09:43:23 +00:00
Rings.Stop();
2025-02-27 04:27:27 +00:00
}
2025-02-07 13:15:29 +00:00
if (Input.GetKey(KeyCode.RightArrow)|| Input.GetKey(KeyCode.H))
2025-02-07 13:15:29 +00:00
{
obj.transform.Rotate(new Vector3(0.0f, speed * Time.deltaTime * rotate_speed , 0.0f));
2025-02-07 13:15:29 +00:00
}
else if (Input.GetKey(KeyCode.LeftArrow)|| Input.GetKey(KeyCode.F))
2025-02-07 13:15:29 +00:00
{
obj.transform.Rotate(new Vector3(0.0f, speed * -Time.deltaTime * rotate_speed, 0.0f));
2025-02-07 13:15:29 +00:00
}
else
{
obj.transform.Rotate(new Vector3(0.0f, 0.0f * Time.deltaTime * rotate_speed, 0.0f));
2025-02-07 13:15:29 +00:00
}
}
}
}