hey there im trying to make a random tree spawner script and was wondering how i could make the "number" int random i tried to o it like i did with the x and z int any help would be much appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class randomspawn : MonoBehaviour
{
public GameObject tree;
public int number;
public int yaxis;
void Start()
{
PlaceTree();
}
void PlaceTree()
{
for (int i = 0; i < number; i++)
{
Instantiate(tree, GeneratedPosition(), Quaternion.identity);
}
}
Vector3 GeneratedPosition()
{
int x, y, z;
x = Random.Range(-1000, 1000);
y = UnityEngine.Random.Range(-yaxis, yaxis);
z = Random.Range(-1000, 1000);
return new Vector3(x, y, z);
}
}
Aucun commentaire:
Enregistrer un commentaire