Skip to content

Instantly share code, notes, and snippets.

@JackDraak
Created March 8, 2016 04:42
Show Gist options
  • Save JackDraak/523cd3fcb907cd52050b to your computer and use it in GitHub Desktop.
Save JackDraak/523cd3fcb907cd52050b to your computer and use it in GitHub Desktop.
RandomFreePosition.cs - snippet of FormationController.cs from 2D Shooter project
Transform RandomFreePosition () {
Transform[] myEmptyChildren = new Transform[transform.childCount];
int inCount = 0;
foreach(Transform childPosition in transform) {
if (childPosition.childCount == 0) {
myEmptyChildren[inCount] = childPosition;
inCount++;
}
}
if (inCount > 0) return myEmptyChildren[Random.Range(0, inCount)];
else return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment