-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCar.cs
37 lines (29 loc) · 868 Bytes
/
Car.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Car : MonoBehaviour
{
[SerializeField] private float speed = 10f;
[SerializeField] private float speedGainPerSecond = 0.2f;
[SerializeField] private float turnSpeed = 200f;
public const string Scene = "Game";
private int steerValue;
void Update()
{
speed += speedGainPerSecond * Time.deltaTime;
transform.Rotate(0f, steerValue * turnSpeed * Time.deltaTime, 0f);
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Obstacle"))
{
SceneManager.LoadScene(FinalScore.Scene);
}
}
public void Steer(int value)
{
steerValue = value;
}
}