I made a little room and a character in my scene. Now that character felt pretty alone in his room, so I made a ‘SpawnCharacter’ script and a UI button to launch it. The room got full quite quick and so my character left the room and stepped on a planet. Now he’s alone again, but my script for spawning him some friends doesnt work outside of the room. I need to make sure that the characters wouldn’t spawn inside the planet. How would I do that?
My SpawnCharacter script for the room:
public class UIController : MonoBehaviour {
public GameObject spawnCharacter;
public Vector3 spawnOrigin;
public Vector3 spawnRange;
public void SpawnCharacter() {
Vector3 spawnPosition = new Vector3(
spawnOrigin.x + Random.Range(-spawnRange.x, spawnRange.x),
spawnOrigin.y + Random.Range(-spawnRange.y, spawnRange.y),
spawnOrigin.z + Random.Range(-spawnRange.z, spawnRange.z));
Quaternion spawnRotation = Quaternion.identity;
GameObject newCharacter = Instantiate(spawnCharacter,
spawnPosition, spawnRotation) as GameObject;
}
}