Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

how do I make smart checkpoints?

$
0
0
I have made checkpoints in unity and they work ok (they respawn the character when the character dies) but all the enemies that my character has killed so far has respawned with the character. How do I make the checkpoint know not to spawn enemies after they die? here is my playerpos script (which makes the player move to the last checkpoint position) public class PlayerPos : MonoBehaviour { private GameMaster GM; void Start() { GM = GameObject.FindGameObjectWithTag("GM").GetComponent(); transform.position = GM.lastCheckpointPos; } } here is my checkpoint script: public class CheckPoint : MonoBehaviour { private GameMaster GM; private void Start() { GM = GameObject.FindGameObjectWithTag("GM").GetComponent(); } private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { GM.lastCheckpointPos = transform.position; } } } here is my Gamemaster script: public class GameMaster : MonoBehaviour { // Start is called before the first frame update private static GameMaster instance; public Vector2 lastCheckpointPos; void Awake() { if(instance == null) { instance = this; DontDestroyOnLoad(instance); } else { Destroy(gameObject); } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles