- Home /
Code Organization
I'm trying to put checkpoints in my game, but I'm not sure if I should put it on the GameManager.cs or create another class for checkpoints.
Answer by tuinal · Jul 30, 2020 at 03:57 PM
It's best to try to think in a prefab based way with extensibility in mind. Long, bespoke 'manager' classes are usually not ideal since they can easily end up bug-prone, fail to use OOP effectively, and become increasingly hard to maintain.
Your ideal is probably to have drag-droppable checkpoint prefabs that you just need to drag+drop to make a new checkpoint.
e.g. a checkPoint script could just be:
void OnTriggerEnter(Collider other){
if(other.tag.Equals("Player"){
GameManager.LastCheckpointPosition = gameObject.transform.position;
}
}
With a static Vector3 LastCheckpointPosition in GameManager used when needed. This means you don't need to mess around with GameManager every time you add a checkpoint.
Thanks mang!!! I didn't though on put the variable as static.