如何使用Unity 3D中的不同位置制作随机预制件?
private void SpawnAllEnemy() {
// For all the prefabs
for (int i = 0; i < Enemy.Length; i++) {
// ... create enemy, set their player number and references needed for control.
Enemy[i].m_Instance = Instantiate(m_EnemyPrefab,
m_Tanks[i].m_SpawnPoint.position,
Enemy[i].m_SpawnPoint.rotation) as GameObject;
Enemy[i].PlayerNumber = i + 1;
Enemy[i].Setup();
}
}
这是方法,但我想随机选择敌人的位置以及随机时间出现的敌人
答案 0 :(得分:0)
您可以在此代码中随机生成生成品GameObject SpawnLocation = (GameObject)Instantiate(EnemyObject, spawnLocation, Quaternion.identity);
答案 1 :(得分:-1)
您可以使用此方法。同样也是这个职位。
GameObject[] prefabs;
Vector3[] enemyPosition;
Instantiate(Random.Range(0, prefabs.Length), Random.Range(0, enemyPosition.Length), Quaternion.Identity)