解決方法を完全には理解できないこの小さな問題に遭遇しました。コードを何度も変更しようとしましたが、どこにも行きませんでした:(
私はプログラムでゲームオブジェクトを作成していますが、これは正常に動作しますが、問題は、ゲームがフレームごとに 1 回オブジェクトを作成することです (私が望むものではありません)。そのため、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);
}
オブジェクトはフレームごとに無限に表示されます -_-
誰かが私を正しい方向に向けるのを手伝ってくれませんか。そして、これを達成するためのより良い方法はありますか?