using UnityEngine; public class TestPrefabs : MonoBehaviour { public GameObject cubeObject; //void Start() //{ // Instantiate(cubeObject, transform.position, transform.rotation); //} void Update() { Instantiate(cubeObject, transform.position, transform.rotation); } }
然后将改脚本挂在到Cube上,成为其组件的一部分,然后将预制体中的Cube填充GameObject cubeObject(将其拖动到public组件框中)