我試圖使用幫助函數爲了使函數暫停幾秒鐘,但它不執行等待函數。在觸發函數內部使用幫助函數
這就是我一直在使用的代碼:
代碼:
public class Triggers : MonoBehaviour {
IEnumerator wait(float seconds) {
Debug.Log("In wait");
yield return new WaitForSeconds(seconds);
Debug.Log("after wait");
}
void OnTriggerEnter(Collider _collider)
{
Debug.Log("Destroy");
gameObject.SetActive(false);
Debug.Log("Before wait");
wait(5);
Debug.Log("activate");
gameObject.SetActive(true);
}
}
我會很感激一些幫助。
幹得好。感謝您發佈最終結果。 ;-) –