Hello Community,
I wanted to ask, if there is a possibility to create a random mountain at the start of the game.
I searched in Google and in this forum, but i couldn’t find something i could directly add to the game.
I am pretty new here and i am using Unity for just a short time now.
Thanks for every help ^^
Here is a little code I just wrote to do something like this. You assign mountain prefabs to the slots in the script (as many as you want: it’s scalable). Next assign your maxs and mins for all axis. Hope this helps
using UnityEngine;
using System.Collections;
public class MountainPlacer : MonoBehaviour
{
public GameObject[] mountains;
public int randomMountain;
public float xPositionMax;
public float xPositionMin;
public float yPositionMax;
public float yPositionMin;
public float zPositionMax;
public float zPositionMin;
// Use this for initialization
void Start ()
{
randomMountain = Random.Range (0, mountains.Length);
Instantiate (mountains [randomMountain], new Vector3(Random.Range(xPositionMin,xPositionMax),Random.Range(yPositionMin,yPositionMax),Random.Range(zPositionMin,zPositionMax)), Quaternion.Euler (Vector3.zero));
}
}