我嘗試在 hp 為 0 或低于 0 后讓粘液消失但是當我攻擊它時,它沒有消失但是 hp 繼續下降 - 我嘗試更改 Destroy 代碼但它仍然沒有用
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
Animator animator;
public float Health {
set {
health = value;
if(health <= 0) {
Defeated();
}
}
get {
return health;
}
}
public float health = 1;
private void Start() {
animator = GetComponent<Animator>();
}
public void Defeated(){
animator.SetTrigger("Defeated");
}
public void RemoveEnemy() {
Destroy(gameObject);
}
}
uj5u.com熱心網友回復:
你不打電話RemoveEnemy()
。您需要等待播放“擊敗”影片,然后呼叫RemoveEnemy()
。
如果您知道影片的長度,則可以更改Defeated()
為協程并等待它,例如:
private IEnumerator Defeated()
{
animator.SetTrigger("Defeated");
yield return new WaitForSeconds(_defeatedAnimLength);
RemoveEnemy();
}
或者,您可以在影片中設定一個觸發器,它將RemoveEnemy()
從影片中呼叫。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/536482.html
標籤:C#unity3d