CapersProject/Assets/02.Scripts/BlueWater/Sail/ShipMove.cs
2025-02-27 13:27:27 +09:00

137 lines
4.3 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 ParticleSystem Smoke1;
[SerializeField]
private ParticleSystem Smoke2;
[SerializeField]
private ParticleSystem Smoke3;
[SerializeField]
private ParticleSystem Smoke4;
[SerializeField]
private ParticleSystem Smoke5;
[SerializeField]
private ParticleSystem Smoke6;
[SerializeField]
private ParticleSystem Smoke7;
[SerializeField]
private ParticleSystem Smoke8;
[SerializeField]
private ParticleSystem Rings;
private void Start()
{
Smoke1.Stop();
Smoke2.Stop();
Smoke3.Stop();
Smoke4.Stop();
Smoke5.Stop();
Smoke6.Stop();
Smoke7.Stop();
Smoke8.Stop();
//Rings.Stop();
}
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.W))
{
force += force_add;
if (force >= 1.0f) force = 1.0f;
}
else if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
{
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)
{
Smoke1.Play();
Smoke2.Play();
Smoke3.Play();
Smoke4.Play();
Smoke5.Play();
Smoke6.Play();
Smoke7.Play();
Smoke8.Play();
//Rings.Play();
}
else
{
Smoke1.Stop();
Smoke2.Stop();
Smoke3.Stop();
Smoke4.Stop();
Smoke5.Stop();
Smoke6.Stop();
Smoke7.Stop();
Smoke8.Stop();
//Rings.Stop();
}
Smoke1.startSize = 0.2f * (force);
Smoke2.startSize = 0.2f * (force);
Smoke3.startSize = 0.2f * (force);
Smoke4.startSize = 0.2f * (force);
Smoke5.startSize = 0.2f * (force);
Smoke6.startSize = 0.2f * (force);
Smoke7.startSize = 0.2f * (force);
Smoke8.startSize = 0.2f * (force);
if (Input.GetKey(KeyCode.RightArrow)|| Input.GetKey(KeyCode.D))
{
obj.transform.Rotate(new Vector3(0.0f, speed * Time.deltaTime , 0.0f));
}
else if (Input.GetKey(KeyCode.LeftArrow)|| Input.GetKey(KeyCode.A))
{
obj.transform.Rotate(new Vector3(0.0f, speed * -Time.deltaTime , 0.0f));
}
else
{
obj.transform.Rotate(new Vector3(0.0f, 0.0f * Time.deltaTime , 0.0f));
}
}
}
}