I made a game where you can spawn multiple objects that can move. but i want to make sure that the spawned object doesnt spawn on a player or a part of the terrain. and if it can’t spawn i want a new spawnrange. this is my code:
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse1))
{
// Makes a random Vector3 and puts it in the spawner. f after numbers means decimal number.
Vector3 spawnrange = new Vector3(Random.Range(-10, 11), Random.Range(-5, 6), 0);
// Instantiate at a random position and zero rotation.
Instantiate(player, spawnrange, Quaternion.identity);
}
}
}