using UnityEngine;
[RequireComponent(typeof(Rigidbody), typeof(BoxCollider))]
public class CarMove : MonoBehaviour
{
[SerializeField] private Rigidbody _rb;
[SerializeField] private float _dashSpeed;
[SerializeField] private float _rotateSpeed;
[SerializeField] private float _rotateSide = 1;
private Vector3 v3;
private void FixedUpdate()
{
CarRotate();
}
private void CarRotate()
{
v3.z += _rotateSide * _rotateSpeed * Time.fixedDeltaTime;
if (v3.z >= 360f)
v3.z -= 360f;
else if (v3.z < 0f)
v3.z += 360f;
transform.rotation = Quaternion.Euler(-90, 0, v3.z);
}
public void RotateCarLeft()
{
_rotateSide = -1;
}
public void RotateCarRight()
{
_rotateSide = 1;
}
public void DashButton()
{
Vector3 dashDirection = transform.forward;
_rb.AddForce(dashDirection * _dashSpeed, ForceMode.Impulse);
}
}