2D碰撞器不会触发

时间:2015-07-02 18:21:30

标签: c# unity3d

enter image description here

我的玩家创造了一个阻挡入侵攻击的障碍,但由于某种原因,对手不会在障碍物上触发,但是当玩家受到伤害并且在被射弹击中时死亡时,它会触发玩家游戏对象。我也试过CollisionEnter,它有相同的结果。我的barrierScript就是这个>

using UnityEngine;
using System.Collections;

public class BarreiraScript : MonoBehaviour {

    // Use this for initialization
    void Start () {
        StartCoroutine("DestroyAfterLoad");
    }

    // Update is called once per frame
    void Update () {

     }
     IEnumerator DestroyAfterLoad()
      {
        yield return new WaitForSeconds(4f);
        Destroy(gameObject); 
      }
      /* void OnCollisionEnter2D (Collision2D other){
        if(other.gameObject.tag == "EnemyFlyng")
        Destroy(other.gameObject);
       }
      */
        void OnTriggerEnter2D(Collider2D other)
      {
        if (other.tag == "EnemyFlyng"){
            Destroy(other.gameObject);

          }
          if (other.tag == "enemyProjetil")
          {
            Destroy(other.gameObject);

          }
          }


          }

enter image description here

1 个答案:

答案 0 :(得分:0)

"enemyProjetil"似乎拼错了,虽然不尝试按标记过滤它,看看它是否有用,然后你会知道你的标签是问题。

相关问题