我試圖製作一個遊戲,在那裏你可以刺傷敵人,敵人掙扎大約一秒鐘後就會死亡。 (布娃娃);如何在查找遊戲對象之前添加延遲
我認爲最好只顯示我的劇本,你知道我的意思:
在觸發器輸入腳本:
if(other.tag == "enemy"){
other.transform.parent.gameObject.name = ("enemy" + currentEnemy);
print(other.name);
gameObject.Find("enemy" + currentEnemy).GetComponent("RagdollOrNot").MakeKinematicFalse();
BloodParticle.emit = true;
Stabbed = true;
Character.GetComponent("MouseLook").enabled = false;
Character.GetComponent("CharacterMotor").enabled = false;
}
,並在更新功能:
if(Stabbed == true){
StopBleeding ++;
}
if(StopBleeding > 50){
Stabbed = false;
StopBleeding = 0;
currentEnemy ++;
Character.GetComponent("MouseLook").enabled = true;
Character.GetComponent("CharacterMotor").enabled = true;
BloodParticle.emit = false;
}
現在,當我的刀進入敵人的碰撞,敵人imediatly下降到地板上。 我試着把:
gameObject.Find("enemy" + currentEnemy).GetComponent("RagdollOrNot").MakeKinematicFalse();
在更新功能if(StopBleeding > 50)
。
如果我這樣做,我會得到一個null reverance異常的錯誤,因爲腳本cand找到了敵人。雖然它可以讓我的觸發器進入。
基本上我的問題是:有沒有辦法解決這個錯誤給它一個50幀的延遲(所有在StopBleeding
作品)?
或者有沒有什麼方法可以在Ragdoll啓動前進行簡單的延遲?
在此先感謝
請注意,這是C#語法。 Unity JS語法完全不需要使用Coroutines。查找Unity JS的「yield」關鍵字。 – scriptocalypse 2011-04-20 23:28:38