Question by
pohshania · Aug 07, 2017 at 05:32 PM ·
c#collision2d-platformerontriggerenter
My OnTriggerEnter2D(Collider2D other) not working
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:
Comment
Answer by niorg2606 · Aug 08, 2017 at 01:43 PM
Have you enabled just the normal logs in the console? Open the console and look at the top right hand corner. You should see 3 icons, a speech bubble, a yellow triangle, and a red octagon. Click the speech bubble.