【发布时间】:2018-05-29 04:21:19
【问题描述】:
我在gameobject 中有两个不同类型的对撞机:一个用于触发器的球体对撞机和一个用于命中射线投射的胶囊对撞机。我有OnTriggerEnter 的代码,但是当玩家进入球体触发器时什么也没有发生。我做错了什么?
public GameObject canvasTesoroFoto;
public GameObject canvasTesoroDatos;
private GameObject Player;
public SphereCollider sCollider;
public CapsuleCollider cCollider;
void Start()
{
Player = GameObject.FindGameObjectWithTag("Player");
sCollider = GetComponent<SphereCollider> ();
cCollider = GetComponent<CapsuleCollider> ();
}
void OnTriggerEnter(Collider other)
{
if (other == sCollider) {
if (other.gameObject.tag == "Player") {
canvasTesoroFoto.SetActive (true);
canvasTesoroDatos.SetActive (true);
}
}
if (other == cCollider) {
Debug.Log ("HitCollider");
return;
}
}
【问题讨论】:
-
这段代码在什么游戏对象中附加?在玩家中还是在障碍物中?
-
@IgnacioAlorre 在障碍中。
-
好的,我编辑了答案。那么只有球体有触发器还是胶囊也有?
-
球体有触发器