Created
March 8, 2016 04:42
-
-
Save JackDraak/523cd3fcb907cd52050b to your computer and use it in GitHub Desktop.
RandomFreePosition.cs - snippet of FormationController.cs from 2D Shooter project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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