0
我在另一個對象附近創建了GameObject。函數「Instantiate」重複自身(進入循環),這就是問題所在。我需要它被稱爲一次。我試過: 1.調用函數按下按鈕(GetKey)。此功能仍然可以創建3-4個對象。 2.在Update和FixedUpdate中添加代碼。而且它還創造了幾個對象。 :(函數進入循環(重複自己)而不是僅僅工作一次
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class table : MonoBehaviour {
public GameObject obj;
public Renderer rend;
void Start() {
rend = GetComponent<Renderer>();
Vector3 center = rend.bounds.center;
Vector3 pos = center + new Vector3 (12,0,0);
Instantiate (obj, pos, Quaternion.identity);
}
}