player reset added
This commit is contained in:
@@ -16,6 +16,9 @@ public class PlayerController : MonoBehaviour
|
||||
public Rigidbody rigidBody;
|
||||
[HideInInspector] public int checkpointsCollected = 0;
|
||||
public GameObject[] checkpoints;
|
||||
Vector3 startPosition;
|
||||
Quaternion startRotation;
|
||||
KeyCode resetCarKey = KeyCode.Backspace;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -24,6 +27,9 @@ public class PlayerController : MonoBehaviour
|
||||
{
|
||||
rigidBody = GetComponent<Rigidbody> ();
|
||||
}
|
||||
|
||||
startPosition = transform.position;
|
||||
startRotation = transform.rotation;
|
||||
|
||||
|
||||
// Find all child GameObjects that have the WheelControl script attached
|
||||
@@ -128,6 +134,35 @@ public class PlayerController : MonoBehaviour
|
||||
float checkpintDistance = distanceToCheckpoint(currentCheckpoint);
|
||||
|
||||
|
||||
// send back to previous checkpoint if stuck
|
||||
|
||||
if (Input.GetKeyDown(resetCarKey))
|
||||
{
|
||||
if (checkpointsCollected == 0)
|
||||
{
|
||||
transform.position = startPosition;
|
||||
transform.rotation = startRotation;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
transform.position = new Vector3(
|
||||
checkpoints[checkpointsCollected - 1].transform.position.x,
|
||||
transform.position.y + 3,
|
||||
checkpoints[checkpointsCollected - 1].transform.position.z
|
||||
);
|
||||
|
||||
transform.eulerAngles = new Vector3(
|
||||
transform.eulerAngles.x,
|
||||
checkpoints[checkpointsCollected - 1].transform.eulerAngles.y,
|
||||
transform.eulerAngles.z
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (checkpintDistance < 0.2f)
|
||||
{
|
||||
checkpointsCollected += 1;
|
||||
|
||||
Reference in New Issue
Block a user