我有用於生成向左,向右和向下移動的旋轉球的代碼。生成點(空物體)設置在地面以上約3個單位,因此它會掉落到地面並向左或向右移動。 我面臨的問題是,在我摧毀了預製的克隆並重置它在原來的位置產卵,並期望它落到地面並移動,但它只在原始位置產生,它不會落入地面。任何幫助將不勝感激。謝謝。 `在銷燬預製件然後重新創建預製件後,新的克隆對象不會移動
public class spawnLemmings : MonoBehaviour {
//this is the number of lemmings that will spawn
private int numLemming = 6;
//Creating a prefab gameObject to attach the prefab to
public GameObject prefab;
// Use this for initialization
void Start() {
Spawn();
}
void FixedUpdate()
{
Reset();
}
void Spawn()
{
//A for loop to create desired number of Lemmings
for (int i = 0; i < numLemming; i++)
{
//This is where the game object is being created
prefab = (GameObject)Instantiate(prefab, transform.position, Quaternion.identity);
//This sets the speed of lemming.
//prefab.GetComponent<lemmingMovement>().speed = Random.Range(3.0f, 4.0f); ///speed = 2.0f;
//This resets onGround to false
//prefab.GetComponent<lemmingMovement>().OnGround();
}
}
void Reset()
{
if (Input.GetKeyDown("r"))
{
GameObject[] lems = GameObject.FindGameObjectsWithTag("Lemmings");
foreach (GameObject lem in lems)
{
Destroy(lem);
}
Spawn();
}
}
}
`
對不起,我忘了刪除FixedUpdate(),我只是測試,看看是否是造成問題。我的代碼使用Update()。 –