Question by
fvpmgameryt · Nov 25, 2017 at 09:50 AM ·
spawnspawnpointsspawning-enemies
how can i spawn enemies with different sprites ?
Hello i have this code but i want to spawn enemies with different sprites what can i do ? i want that enemy's spawn with random sprites in random positions
public class spawn : MonoBehaviour {
public GameObject fruitPrefab;
public Transform[] spawnPoints;
public float minDelay = .1f;
public float maxDelay = 1f;
// Use this for initialization
void Start () {
StartCoroutine (SpawnFruits ());
}
IEnumerator SpawnFruits(){
while (true) {
float delay = Random.Range (minDelay, maxDelay);
yield return new WaitForSeconds (delay);
int spawnIndex = Random.Range (0, spawnPoints.Length);
Transform spawnPoint = spawnPoints [spawnIndex];
GameObject spawedFruit = Instantiate (fruitPrefab, spawnPoint.position, spawnPoint.rotation);
Destroy (spawedFruit, 3f);
}
}
Comment
Best Answer
Answer by OpenMindStudios · Nov 25, 2017 at 04:59 PM
have a list of all the different enemy prefabs and have it randomly choose a prefab from the list.
Your answer

Follow this Question
Related Questions
How to identify players on Photon Unity? 2 Answers
problem when i spawn to many Enemy the game be slower 1 Answer
Instantiate isnt working for spawner class 1 Answer
(17,37): error CS0841: A local variable `spawnPointIndex' cannot be used before it is declared 1 Answer
How to spawn objects from the right side outside of view range? 0 Answers