Skip to content

Instantly share code, notes, and snippets.

@Henry-E
Created June 9, 2015 10:11
Show Gist options
  • Save Henry-E/148041a6f23026d01677 to your computer and use it in GitHub Desktop.
Save Henry-E/148041a6f23026d01677 to your computer and use it in GitHub Desktop.
// all this code needs to go in the loop which initialises the asteroids
bool isStillCheckingLocation = true;
while(isStillCheckingLocation)
{
asteroidStartLocation = new Vector2 (UnityEngine.Random.Range (0, gameWidth),
UnityEngine.Random.Range (0, gameHeight));
// we need to make sure the asteroids are not spawned too close to the player
if( (asteroidStartLocation.x < gameWidth * 0.4f || asteroidStartLocation.x > gameWidth * 0.6f) &&
(asteroidStartLocation.y < gameHeight * 0.4f || asteroidStartLocation.y > gameHeight * 0.6f) )
isStillCheckingLocation = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment