【发布时间】:2015-10-16 14:09:39
【问题描述】:
我有代码可以生成一个向左、向右移动并落下的旋转球。生成点(空物体)设置在离地面约 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()。