- Home /
Need help with randomizing starting location of terrains
Hello everyone! I've just starting programming and I've hit a roadblock. I have written a code which instantiates 8 terrains at 8 starting positions. Whenever the game is launched, these 8 terrains shuffle between each other. Here is the code I used:
public class StartingPosition : MonoBehaviour {
public List<GameObject> Terrains; //create array for terrains
public Transform[] TerrainsPositions; //for the predetermined position of the terrains
// Use this for initialization
void Start () {
foreach (Transform CurrentTerrainPosition in TerrainsPositions)
{
int randomTerrain = UnityEngine.Random.Range(0,Terrains.Count);
Instantiate(Terrains[randomTerrain], CurrentTerrainPosition.transform.position, CurrentTerrainPosition.transform.rotation);
Terrains.RemoveAt(randomTerrain);
}
What I want to do is this: I want to have 8 starting locations with an array of 3 terrains each. Of these 3 terrains, there will always be a default one which will instantiate under normal circumstances. However, I want the code to pick 3 of the 8 starting locations at random and for those starting locations randomly instantiate 1 of the 3 terrain options I mentioned. This way, whenever the game is launched, the map will not be the same and there will be a lot of variety and incentive for the player to explore.
I think I have an idea of how to use the code I have to create the array of the 3 terrain options for each of the 8 starting positions, but I have no idea how to randomly apply these changes to 3 of the 8 terrains only and how to chose the default one if the starting positions isn't part of the 3 which were chosen by the code.
Any help will be appreciated. Thanks in advance!
Your answer
Follow this Question
Related Questions
Spawning above the terrain 2 Answers
Random Terrain in 2d Game? 0 Answers
Any Reason this would make Unity Freeze up? 0 Answers
Placing Buildings on Terrain 1 Answer
Tree position on random Terrain (y axis) 0 Answers