我已經遇到這個小問題,我似乎不能完全理解怎麼解決,我試圖改變我的代碼無數次,但我還沒有得到任何地方:(如何阻止GameObjects在每一幀重新渲染?
我創建的遊戲對象編程工作正常,但問題是,遊戲創造每幀(不正是我想要的)一次的對象!所以,我已經把10秒的時間延遲,但它似乎沒有正常工作。
public Vector3 spawnLocation;
public GameObject myCube;
// Use this for initialization
void Start() {
if (myCube.renderer.enabled == false) {
Debug.Log("myCube not rendered");
myCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
}
if (myCube == null) {
Debug.Log("myCube not set");
myCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
}
}
// Update is called once per frame
void Update() {
StartCoroutine(Delay());
Destroy(myCube, 5);
CreateCube();
}
void CreateCube() {
spawnLocation = new Vector3(24, 17, -28);
StartCoroutine(Delay());
Instantiate(myCube, spawnLocation, Quaternion.identity);
}
IEnumerator Delay(){
yield return new WaitForSeconds(10);
}
的對象在每一幀-_-
任何人都可以請幫點m出現不休e在正確的方向去哪裏。 有沒有更好的方法來實現這一目標?
你調用'CreateCube()'每次遊戲循環。把它放在'Start()'中。 – David 2013-05-01 19:52:06
@大衛我試過了,但如果我把'CreateCube()''中開始()'它僅創建遊戲對象一次!我想不停地創建'myCube',但是需要一定的時間間隔。 – Ange 2013-05-01 20:08:15
// Update()每幀調用一次。如果你是新手,直到你學習如何實現一個事件模式或者你會遇到噩夢,那就避免使用它。 – 2013-05-01 20:18:55