I want to place objects at random locations within the bounds of a detected plane via a Spawner script. My problem is that I am not being able to figure out a way to make sure that the locations from where the objects are spawned always takes place at any random location within the detected plane surface.
For eg) If I scan a ground plane I want game objects to spawn on that ground plane
How can I utilize the WorldInterpreter script and the Floor game object to do so?
My Spawner Script -
public class Spawner : MonoBehaviour
{
[SerializeField]
private GameObject myPrefab;
public float minWait;
public float maxWait;
public float offset = 3;
private bool isSpawning;
void Awake()
{
isSpawning = false;
}
void Update()
{
if (!isSpawning)
{
float timer = Random.Range(minWait, maxWait);
Invoke("SpawnObject", timer);
isSpawning = true;
}
}
void SpawnObject()
{
float randX = Random.Range(-offset,offset);
float randZ = Random.Range(-offset,offset);
Instantiate(myPrefab,new Vector3(randX,transform.position.y,randZ),Quaternion.identity);
isSpawning = false;
}
}