Hi. So im trying to make a checkpoint system that when you die you respawn at the latest checkpoint. Im using one script that is gonna handle the switching of the one you will respawn at. And another script that handles the respawn at the right checkpoint position.
This is the script that handles the switching of index.
public class CheckPointHandler : MonoBehaviour {
public List<Check> checkPoints = new List<Check> {};
public int currentCheck;
//public static GameObject[] checkPointsList;
//public bool active = false;
// int currentIndex;
// public List<Check> CheckPoints { get { return CheckPoints; } }
// public Check curentCheckPoint { get { return CheckPoints[currentIndex]; } }
// public static CheckPointHandler Instance { get { return Instance; } }
// List<Check> checkpoints = new List<Check>();
// int curIndex = 0;
// static CheckPointHandler instance = null;
//// protected override void Awake()
// //{
// //instance = this;
// //for(int i=0; i <transform.childCount;i++)
// //{
// //Check checkpoint = transform.GetChild(i).GetComponent<Check>();
// //checkpoint.onTrigger += onCheckPointTriggered;
// //checkpoints.add(checkpoint);
// //}
//// }
// //public void onCheckpointTriggered(Check newcheckpoint)
// //{
// // curIndex = chekcpioint.indexOf(newCHeckPoint);
// //}
// Use this for initialization
void Start () {
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Checkpoint");
{
for (int i = 0; i < 5; i++)
{
print("Hel Aliens");
print(checkPoints[i]);
}
}
}