For some reason my checkpoints are not working in my 2D platformer game, the checkpoint is meant to be activated when the player collides with it but for some reason, the checkpoint doesn't activate and the player just respawns at the first checkpoint. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Checkpoint : MonoBehaviour { public GameMaster gameMaster; // Start is called before the first frame update void Start() { gameMaster = FindObjectOfType<GameMaster>(); } void OnTriggerEnter2D(Collider other) { if (other.gameObject.tag == "Player") { gameMaster.spawnPoint = gameObject.transform; } } } Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameMaster : MonoBehaviour { public static GameMaster gm; public Transform playerPrefab; public Transform spawnPoint; // Start is called before the first frame update void Start() { if (gm == null) { gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>(); } } public void RespawnPlayer() { Debug.Log("Player Respawn"); playerPrefab.transform.position = spawnPoint.transform.position; } } Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Dead : MonoBehaviour { public GameMaster gameMaster; void Start() { gameMaster = FindObjectOfType<GameMaster>(); } void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { Debug.Log("Died"); gameMaster.RespawnPlayer(); other.gameObject.GetComponent<PlayerMovement>().Die(); } } } I am a beginner at unity and c# so if someone could please help it would be much appreciated.
Inside Checkpoint script you have Code (CSharp): void OnTriggerEnter2D(Collider other) { if (other.gameObject.tag == "Player") { gameMaster.spawnPoint = gameObject.transform; } } Fix it writing void OnTriggerEnter2D(Collider2D other)
Oooh good eye!! Also, to OP, when you have weird "just doesn't work" type problems, always put lots of Debug.Log() statements in all over so you know what is executing and what isn't. In this case the incorrect signature that Nyfirex noted above would definitely cause that method to never get called, and that would draw your attention immediately to that function.