public class Driver : MonoBehaviour
{
[SerializeField]
private float _steerSpeed = 300f;
[SerializeField]
private float _moveSpeed = _defaultMoveSpeed;
private const float _defaultMoveSpeed = 20f;
[SerializeField]
private float _slowSpeed = 15f;
[SerializeField]
private float _boostSpeed = 30f;
private const int _duration = 3;
void Update()
{
float steerAmount = Input.GetAxis("Horizontal") * _steerSpeed * Time.deltaTime;
float moveAmount = Input.GetAxis("Vertical") * _moveSpeed * Time.deltaTime;
transform.Rotate(0, 0, -steerAmount);
transform.Translate(0, moveAmount, 0);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == "SpeedUp")
{
Debug.Log("Ka-Chow!");
_moveSpeed = _boostSpeed;
var thread = new Thread(new ThreadStart(dur));
thread.Start();
}
}
private void dur()
{
Thread.Sleep(_duration * 1000);
_moveSpeed = _defaultMoveSpeed;
}
private void OnCollisionEnter2D(Collision2D collision)
{
_moveSpeed = _slowSpeed;
var thread = new Thread(new ThreadStart(dur));
thread.Start();
}
}