ASTEROIDS - RANDOM SPAWN
INSTANTIATE RANDOM ASTEROIDS
This section discusses on how the random (out of 3 prefabs) asteroids were instantiated at random x-position using asteroid prefabs' rotation.
RANDOM INDEX FOR ARRAY
It is necessary to create a random index for an array so that every time the Game Object is instantiated, a random Index in fed into the code and random asteroid clone is created.
For this, Random.Range(int minInclusive, int maxExclusive) was used.
This method is used to return a random int within [minInclusive and maxExclusive]
In this case, minInclusive number = 0, and
maxExclusive number = Array.Length (Length of an array or number of elements stored in an array)
RANDOM SPAWN POSITION
The random asteroids should spawn from random x-position. However, y and z position is fixed.
To get random x-position, a Random.Range() method was used again.
The random x-position, and y and z -position were then used to create a new Vector3. This was stored in a Vector3 variable randomSpawnPosition.
INSTANTIATE
Both, the randomIndex for random asteroid instantiation and randomSpawnPosition was created.
Now, using Instantiate() method, random asteroids were instantiated.
SpawnAsteroids() method
To make the script more readable, a new method SpawnAsteroids() was created that would just handle the random instantate function of asteroids.
...PROGRESS SO FAR...