Advertisement
gandalfbialy

Untitled

Jun 21st, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class CheckpointController : MonoBehaviour
  4. {
  5. public int lap = 0;
  6. public int checkpoint = -1;
  7. int checkpointCount;
  8. public int nextCheckpoint;
  9.  
  10. void Start()
  11. {
  12. GameObject[] checkpoints = GameObject.FindGameObjectsWithTag("Checkpoint");
  13. checkpointCount = checkpoints.Length;
  14. }
  15.  
  16. private void OnTriggerEnter(Collider other)
  17. {
  18. if (other.gameObject.tag == "Checkpoint")
  19. {
  20. int thisCheckpoint = int.Parse(other.gameObject.name);
  21.  
  22. if (thisCheckpoint == nextCheckpoint)
  23. {
  24. checkpoint = thisCheckpoint;
  25.  
  26. if (checkpoint == 0)
  27. {
  28. lap++;
  29. Debug.Log("Lap: " + lap);
  30. }
  31.  
  32. nextCheckpoint++;
  33. nextCheckpoint = nextCheckpoint % checkpointCount;
  34. }
  35. }
  36. }
  37.  
  38. // Update is called once per frame
  39. void Update()
  40. {
  41.  
  42. }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement