OnTriggerEnter not working

后端 未结 1 2010
别跟我提以往
别跟我提以往 2021-01-25 09:10
public var enemy:GameObject;

enemy = GameObject.FindGameObjectWithTag(\"enemy\");

function OnTriggerEnter(other:Collider)
{
   if(other.gameObject.tag == \"enemy\")
           


        
相关标签:
1条回答
  • 2021-01-25 09:30

    If you use the 2D physics engine, you need to use the 2D functions:

    function OnTriggerEnter2D(other: Collider2D) 
    {
        if(other.tag == "enemy")
        {
            Debug.Log("Dead");
            Destroy(gameObject);
        }
    }
    
    0 讨论(0)
提交回复
热议问题