Hi there, I have a script which I attached it to my obstacles, and when the player collides with the obstacles, a debug log should print out a message “Player Respawn”. However, my OnTriggerEnter2D in the script is not working and I dont know why. Can someone help me please?
public class KillPlayer : MonoBehaviour {
public LevelManger levelManager;
// Use this for initialization
void Start ()
{
levelManager = FindObjectOfType<LevelManger>();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
levelManager.RespawnPlayer();
}
}
}
And below is the script for LevelManger:
public class LevelManger : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void RespawnPlayer()
{
Debug.Log("Player Respawn");
}
}
And this is my player:
And this is my obstacle which I attached KillPlayer script to: