0
我正在製作一個A.I角色走向玩家。一旦collider2D通過使用Add force進入玩家並且效果很好並且花花綠綠,但是當A.I退出玩家collider2D時,它會繼續添加力量。所以我加了onTriggerExit2D()來使力0或停止應用它。onTriggerExit2D()不工作? unity2D c#
出於某種原因,從不退出觸發器我已經使用調試,但沒有任何顯示。
void Update() {
if (canHearPlayer)
{
rigidbody2D.AddForce (new Vector2 (-force, 0));
}
if (!canHearPlayer)
{
force = 0;
}
}
void FixedUpdate()
{
}
void OnTriggerEnter2D(Collider2D other){
Debug.Log(gameObject.name + " was hit by " + other.gameObject.name);
if (other.gameObject.name == "New_Player")
{
canHearPlayer = true;
force = 3f;
}
}
void onTriggerExit2D(Collider2D other)
{
if (other.gameObject.name == "New_Player")
{
canHearPlayer = false;
Debug.LogWarning (canHearPlayer + "Trigger has been exited");
}
}
錯字? OnTriggerExit2D需要一個大寫字母「O」 –