Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sasherafat-zz/50b02b51e6a44dcd5328ec6efb828d25 to your computer and use it in GitHub Desktop.
Save sasherafat-zz/50b02b51e6a44dcd5328ec6efb828d25 to your computer and use it in GitHub Desktop.
Spanw Function
void Spawn() {
// x position between left & right border
int x = (int)Random.Range(borderLeft.position.x,
borderRight.position.x);
// y position between top & bottom border
int y = (int)Random.Range(borderBottom.position.y,
borderTop.position.y);
// Instantiate the food at (x, y)
Instantiate(foodPrefab,
new Vector2(x, y),
Quaternion.identity); // default rotation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment