- Home /
Question by
Davidbillmanoy · Mar 29, 2021 at 09:15 PM ·
checkpointcheckpoints
Checkpoint System
Hello! I put the script in all checkpoints. When the car passes the first checkpoint, it will go straight to the first one or the last one. Can anyone help me?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CheckpointScript : MonoBehaviour
{
public GameObject LapCompleteTrig;
public GameObject Checkpoint1;
public GameObject Checkpoint2;
public GameObject Checkpoint3;
public int CheckpointTracker;
//When the car passes the first checkpoint, the checkpoint goes straight to the first one or the last one.
//After the car passes the last checkpoint, the checkpoint stays in place.
void Update()
{
if (CheckpointTracker == 0)
{
LapCompleteTrig.SetActive(false);
Checkpoint1.SetActive(true);
Checkpoint2.SetActive(false);
Checkpoint3.SetActive(false);
}
if (CheckpointTracker == 1)
{
LapCompleteTrig.SetActive(false);
Checkpoint1.SetActive(false);
Checkpoint2.SetActive(true);
Checkpoint3.SetActive(false);
}
if (CheckpointTracker == 2)
{
LapCompleteTrig.SetActive(false);
Checkpoint1.SetActive(false);
Checkpoint2.SetActive(false);
Checkpoint3.SetActive(true);
}
if (CheckpointTracker == 3)
{
LapCompleteTrig.SetActive(true);
Checkpoint1.SetActive(false);
Checkpoint2.SetActive(false);
Checkpoint3.SetActive(false);
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
CheckpointTracker += 1;
if (CheckpointTracker == 4)
{
CheckpointTracker = 0;
}
}
}
}
Comment
Your answer

Follow this Question
Related Questions
If Dead,Checkpoint and reset 2 Answers
Restarting game from last checkpoint. 1 Answer
GUI Label not drawing on screen 0 Answers
Why doesnt my checkpoint system work? 1 Answer
Spawning Script Error 1 Answer