How can i spawn a prefab on voxel terrain in random places?
public GameObject[ ] treesAndRokets;
public GameObject nn;
public int randomHighest;
public Vector3 Radrus;
public Vector3 randomPos;
int x;
float timer;
public bool start = false;
public Vector2 RandoM;
void Start()
{
randomPos.x += Radrus.x*-1/2;
randomPos.z += Radrus.z*-1/2;
}
void Update()
{
if (start == true)
{
timer += Time.deltaTime;
if (randomPos.z < Radrus.z / 2 && timer > 0.05f)
{
Instantiate(treesAndRokets[Random.Range(0, randomHighest)], randomPos + transform.position, transform.rotation);
randomPos.x += Random.Range(RandoM.x, RandoM.y);
randomPos.z = Random.Range(RandoM.x + x, RandoM.y + x) + Radrus.z * -1 / 2;
if (randomPos.x >= Radrus.x / 2)
{
x += 20;
randomPos.x += (Radrus.x * -1) / 2;
randomPos.x += (Radrus.x * -1) / 2;
}
timer = 0;
}
}
}
void OnDrawGizmosSelected()
{
Gizmos.color = Color.green;
Gizmos.DrawWireCube(transform.position,Radrus);
}