0
我設置了一個非常簡單的場景,其中預製件每x秒實例化一次。我在Update()
函數中應用了transform.Translate實例。一切正常,直到第二個對象產生,第一個停止移動,所有的實例停在我的翻譯價值。Unity 3D Instantiated Prefabs stop moving
這裏是我的腳本,連接到一個空的遊戲對象:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public GameObject prefab;
private Transform prefabInstance;
void spawnEnemy() {
GameObject newObject = (GameObject)Instantiate(prefab.gameObject, transform.position, transform.rotation);
prefabInstance = newObject.transform;
}
void Start() {
InvokeRepeating ("spawnEnemy", 1F, 1F);
}
void Update() {
if (prefabInstance) {
prefabInstance.transform.Translate (new Vector3(4,0,0) * Time.deltaTime);
}
}
}
或者,使用'列表'保留所有的實例化的預製件的軌道 –
謝謝你的解釋,它的工作:) – user3712883