Random tree spawn

Hi,
I’m total new in Unity and i just now the basics. I want to make a simple survival game. I already have 3 types of trees, but here’s my problem :

I want to place the trees randomly on my terrain every time a new game is started. But the trees should only spawn in a curtain area.I’m also trying to spawn one tree every day in game or something.

I haven’t found anything useful yet. Can you please give me some clues how I can manage this?

Thank you ,
Sakuron :slight_smile:

You need to get the height of the Terrain

 float height = Terrain.activeTerrain.SampleHeight(rock.transform.position);
Vector3 RandomSpawn = new Vector3(Random.Range(50, 1000), height, Random.Range((50,1000));

This should get you started.

like i said before in your other post use this script:

using UnityEngine;
using System.Collections;

public class test : MonoBehaviour {
    public GameObject tree;
    public int number;
    public int xaxis;
    public int yaxis;
    public int zaxis;

    void Start () {
   
        PlaceTree ();}
    void PlaceTree(){
        for(int i = 0; i < number;i++){
            Instantiate(tree,GeneratedPosition(),Quaternion.identity);
        }
    }
    Vector3 GeneratedPosition(){
        int x,y,z;
        x = UnityEngine.Random.Range (-xaxis, xaxis);
        y = UnityEngine.Random.Range (-yaxis, yaxis);
        z = UnityEngine.Random.Range (-zaxis, zaxis);
        return new Vector3 (x,y,z);

    }
}