done
This commit is contained in:
parent
3a7ce962e7
commit
058e61a4fd
38 changed files with 3915 additions and 363 deletions
37
TP3/Assets/Scripts/CarThings/CheckpointCheck.cs
Normal file
37
TP3/Assets/Scripts/CarThings/CheckpointCheck.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class CheckpointCheck : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
|
||||
public const int MAX_LAPS = 3;
|
||||
[HideInInspector] public int NumberOfLaps { get; private set; } = 0;
|
||||
|
||||
private int currentCheckPointIndex = 0;
|
||||
private int numberOfCheckpoints;
|
||||
void Start()
|
||||
{
|
||||
numberOfCheckpoints = Object.FindObjectsByType<Checkpoint>(FindObjectsSortMode.None).Length;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider collision)
|
||||
{
|
||||
print("Collision");
|
||||
if (!collision.gameObject.TryGetComponent(out Checkpoint checkpoint)) return;
|
||||
|
||||
if (checkpoint.Index == currentCheckPointIndex) currentCheckPointIndex++;
|
||||
|
||||
if (currentCheckPointIndex == numberOfCheckpoints)
|
||||
{
|
||||
currentCheckPointIndex = 0;
|
||||
NumberOfLaps++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue