using Cinemachine; using UnityEngine; using UnityEngine.InputSystem; namespace _02.Scripts.WaterAndShip { [RequireComponent(typeof(Rigidbody))] [RequireComponent(typeof(PlayerInput))] public class Player : MonoBehaviour { public float maxSpeed = 10f; public float acceleration = 2f; public float deceleration = 2f; public float turnSpeed = 10f; private Rigidbody rb; private Vector2 movementInput; private bool isAssaultMode; private void Awake() { rb = GetComponent(); } private void FixedUpdate() { MovePlayer(); RotatePlayer(); } #region AssaultMode/DreadgeMode Switch public void OnModeChange(InputValue value) { if (isAssaultMode) { SwitchToDredgeMode(); } else { SwitchToAssaultMode(); } } private void SwitchToDredgeMode() { GameManager.Inst.CameraController.CamDredgeMode(); GameManager.Inst.UiController.uiAnimator.Reverse(); isAssaultMode = false; } private void SwitchToAssaultMode() { GameManager.Inst.CameraController.CamAssaultMode(); GameManager.Inst.UiController.uiAnimator.Play(); isAssaultMode = true; } #endregion #region Movement public void OnMove(InputValue value) { movementInput = value.Get(); } private void MovePlayer() { var desiredVelocity = transform.forward * movementInput.y * maxSpeed; var speedChange = (movementInput.y != 0 ? acceleration : deceleration) * Time.fixedDeltaTime; rb.velocity = Vector3.MoveTowards(rb.velocity, desiredVelocity, speedChange); } private void RotatePlayer() { var turn = movementInput.x; var turnRotation = Quaternion.Euler(0f, turn * turnSpeed, 0f); rb.MoveRotation(rb.rotation * turnRotation); } #endregion } }