- Home /
How do I create a good Checkpoint system?
Right now I am working on a 2D platformer project. There I managed to get a player, some enemy turrets and some human enemies who are walking around and shoot at the player when they see them. Right now I want to implement an checkpoint system. I have tried out several ways, but all of them ended in nonsense or tons of errors.
My best ideas:
Make a checkpoint script with a list and add all the enemies left from the checkpoint to the list. Then, if the player collides with the checkpoint, check if all the enemies have been killed. If that is true, it activates the checkpoint.
Make an empty object in my world with two lists: checkpoints and enemies. On start, every checkpoint and enemy adds himself to his list. If the player collides with the checkpoint, check if all the enemies have been killed. If that is true, it activates the checkpoint. (Yes, I just copy/pasted that)
My problems:
Method: My script has problems with the "left from checkpoint" as it adds random enemies which are placed right from the checkpoint.
Method, 1. Problem: Unity does not like this:
public Ingamestats InGameStats; public void start() { InGameStats = GetComponent<Ingamestats>(); InGameStats.Enemies.Add(gameObject); }
(Enemies is the public list in the Ingamestats script)
Unity throws errors at me and the lists stay with 0 objects inside.
2.Method, 2. Problem: I have no clue how to choose which enemies do have to get killed to activate the checkpoint.
Additional Problem: When the player dies, teleporting him to the checkpoint is easy. But killing all the enemies left from the checkpoint causes errors too.
I appreciate any help / ideas.