Hello everybody! I need an idea of how to create a checkpoint system that saves checkpoints as you move along. I’ve been trying (and failing) at making an efficient system. Any ideas work! Thanks in advance!
Put some colliders, put all of them in an array, from first to last. Then in script do like this :
THE CODE IS NOT TESTED, BUT IT WILL WORK FOR SURE
//index is going to be each element in array. Its going to be loaded from what we save later.
int index;
Transform[] checkpoints;
void Start(){
index = PlayerPrefs.GetInt("checkPointIndex");
}
void OnCollisionEnter(Collision other){
if(other.gameObject.transform == checkPoints[index]){
index++;
PlayerPrefs.SetInt("checkPointIndex", index);
}
}
The checkpoint system needs to be tailored to your game, so it’s hard to help you come up with good ideas without knowing more.
Some good methods might include keeping a reference to a checkpoint when you activate it. Another good method would be to have a list of checkpoints and remember which index in the list you’ve most recently activated.
Hi! I have writen a post about a checkpoints system in my blog: https://santiandrade.github.io/Unity-Creating-a-checkpoints-system/
I think it will help you! ![]()