OnTriggerEnter2D is not being called

后端 未结 1 745
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-12 03:21

I am trying to make a replica of Asteroids in Unity. The problem is that my bullets are not triggering the OnTriggerEnter2D method on the asteroids. The asteroi

相关标签:
1条回答
  • 2020-12-12 03:46

    The problem is the Spelling. The o in onTriggerEnter2D should be capitalized. Simple mistake like this one can ruin your day. I didn't even notice it until I ran your code.

    void OnTriggerEnter2D(Collider2D collider)
    {
        Debug.Log(collider);
    }
    

    Next time if you are not sure about the spelling of the Unity callback function, right click in Visual Studio then click Implement MonoBehaviours search for the function you want, select it and click OK. Visual Studio will add that function for you.

    0 讨论(0)
提交回复
热议问题