Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.ComponentModel;
- using Unity.VisualScripting;
- using UnityEngine;
- public class RaceController : MonoBehaviour
- {
- public int timer = 3;
- public static int totalLaps = 2;
- public static bool isRacing = false;
- public CheckpointController[] carsControllers;
- void CountDown()
- {
- Debug.Log("Rozpoczynam odlicanie");
- if (timer < 0)
- {
- Debug.Log("Rozpoczęcie wyścigu za: " + timer);
- timer--;
- }
- else
- {
- Debug.Log("Start!");
- isRacing = true;
- CancelInvoke("CountDown");
- }
- }
- void Start()
- {
- InvokeRepeating("CountDown", 3, 1);
- GameObject[] cars = GameObject.FindGameObjectsWithTag("Car");
- carsControllers = new CheckpointController[cars.Length];
- for (int i = 0; i < cars.Length; i++)
- {
- carsControllers[i] = cars[i].GetComponent<CheckpointController>();
- }
- }
- private void LateUpdate()
- {
- int finishedLap = 0;
- foreach(CheckpointController controller in carsControllers)
- {
- if (controller.lap == totalLaps + 1)
- {
- finishedLap++;
- }
- if (finishedLap == carsControllers.Length && isRacing)
- {
- Debug.Log("Wyścig skończony");
- isRacing = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement