Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

How to reduce the chances of a particular enemy spawning ?

$
0
0
I have an array of enemy prefabs inside which, I'm adding the different kinds of enemies I want it to spawn. Currently it spawns any enemy it wants to and there is no control over how many times I want a particular enemy to spawn. How do I make it so that a particular enemy spawns rarely ? Here is my current code: public float spawnTime = 5f; // The amount of time between each spawn. public float spawnDelay = 3f; // The amount of time before spawning starts. public GameObject[] enemies; // Array of enemy prefabs. void Start () { // Start calling the Spawn function repeatedly after a delay . InvokeRepeating("Spawn", spawnDelay, spawnTime); } void Spawn () { // Instantiate a random enemy. int enemyIndex = Random.Range(0, enemies.Length); Instantiate(enemies[enemyIndex], transform.position, transform.rotation); }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>