【发布时间】:2015-07-03 03:19:39
【问题描述】:
我的玩家创建了一个屏障来阻挡来袭的攻击,但由于某种原因,对撞机不会在屏障上触发,但玩家的游戏对象触发得很好,因为他受到伤害并在被射弹击中时死亡。我也尝试了 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);
}
}
}
【问题讨论】:
-
确保仔细检查您的标签。