Advertisement
gandalfbialy

Untitled

Jun 21st, 2025
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. using System.ComponentModel;
  2. using Unity.VisualScripting;
  3. using UnityEngine;
  4.  
  5. public class RaceController : MonoBehaviour
  6. {
  7. public int timer = 3;
  8. public static int totalLaps = 2;
  9. public static bool isRacing = false;
  10.  
  11. public CheckpointController[] carsControllers;
  12.  
  13. void CountDown()
  14. {
  15. Debug.Log("Rozpoczynam odlicanie");
  16.  
  17. if (timer < 0)
  18. {
  19. Debug.Log("Rozpoczęcie wyścigu za: " + timer);
  20. timer--;
  21. }
  22. else
  23. {
  24. Debug.Log("Start!");
  25. isRacing = true;
  26. CancelInvoke("CountDown");
  27. }
  28. }
  29.  
  30. void Start()
  31. {
  32. InvokeRepeating("CountDown", 3, 1);
  33.  
  34. GameObject[] cars = GameObject.FindGameObjectsWithTag("Car");
  35. carsControllers = new CheckpointController[cars.Length];
  36.  
  37. for (int i = 0; i < cars.Length; i++)
  38. {
  39. carsControllers[i] = cars[i].GetComponent<CheckpointController>();
  40. }
  41. }
  42.  
  43. private void LateUpdate()
  44. {
  45. int finishedLap = 0;
  46.  
  47. foreach(CheckpointController controller in carsControllers)
  48. {
  49. if (controller.lap == totalLaps + 1)
  50. {
  51. finishedLap++;
  52. }
  53.  
  54. if (finishedLap == carsControllers.Length && isRacing)
  55. {
  56. Debug.Log("Wyścig skończony");
  57. isRacing = false;
  58. }
  59. }
  60. }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement