Question by
Silveralby · Nov 06, 2019 at 07:52 AM ·
scripting problemscript.
Player Lap System (Racing Game)
Hi guys I have this script for counting the player's laps in a racing game. How can I add the condition that if the player does not arrive first he must repeat the track, while if he wins he goes to the next track and then to the next scene? The car controller is Realistic Car Controller. Thank's
[SerializeField] private string LoadLevel;
public Transform[] checkPointArray;
public static Transform[] checkpointA;
public static int currentCheckpoint = 0;
public static int currentLap = 0;
public Vector3 startPos;
public int Lap;
public Text Giri;
public Text Fine_Gara;
void Start()
{
startPos = transform.position;
currentCheckpoint = 0;
currentLap = 0;
}
bool coroutineStarted; //Aggiungi questo bool
void Update()
{
Lap = currentLap;
checkpointA = checkPointArray;
Giri.text = "Giri: " + currentLap.ToString();
if (currentLap > 3 && !coroutineStarted) //Se currentLap è maggiore di 3 e la courutine non è già partita
{
coroutineStarted = true; //Segna la courutine come già partita
Fine_Gara.text = "Fine Gara";
StartCoroutine(Delay());
}
}
IEnumerator Delay()
{
yield return new WaitForSeconds(3f);
SceneManager.LoadScene(LoadLevel);
}
}
Comment
Your answer
Follow this Question
Related Questions
Why is the code below not setting the value for the timer? 0 Answers
Update() and FixedUpdate() not running on C# scripts 0 Answers
Assigning a PreFab to a pre existing variable. 0 Answers
Creating Splines from empties in script 0 Answers
error CS0246 1 Answer