OldBlueWater/BlueWater/Assets/02.Scripts/WaterAndShip/Player.cs
2023-08-03 10:03:08 +09:00

37 lines
951 B
C#

using UnityEngine;
using UnityEngine.InputSystem;
namespace _02.Scripts.WaterAndShip
{
public class Player : MonoBehaviour
{
public float speed = 10f;
public float turnSpeed = 10f;
private Rigidbody rb;
private Vector2 movementInput;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
public void OnMove(InputValue value)
{
movementInput = value.Get<Vector2>();
}
void FixedUpdate()
{
Vector3 movement = new Vector3(movementInput.x, 0.0f, movementInput.y);
// Move the boat
rb.AddForce(movement * speed * Time.fixedDeltaTime, ForceMode.VelocityChange);
// Rotate the boat
float turn = movementInput.x;
Quaternion turnRotation = Quaternion.Euler(0f, turn * turnSpeed, 0f);
rb.MoveRotation(rb.rotation * turnRotation);
}
}
}