Last active
December 26, 2015 05:09
-
-
Save brunomikoski/7098783 to your computer and use it in GitHub Desktop.
How to search for a gameobject inside another hierarchy.
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
public static class Extensions | |
{ | |
public static Transform Search(this Transform target, string name) | |
{ | |
if (target.name == name) return target; | |
for (int i = 0; i < target.childCount; ++i) | |
{ | |
var result = Search(target.GetChild(i), name); | |
if (result != null) return result; | |
} | |
return null; | |
} | |
public static Vector3 NormalizeAngles (this Vector3 angles) | |
{ | |
angles.x = NormalizeAngle (angles.x); | |
angles.y = NormalizeAngle (angles.y); | |
angles.z = NormalizeAngle (angles.z); | |
return angles; | |
} | |
public static float NormalizeAngle (this float angle) | |
{ | |
while (angle>360) | |
angle -= 360; | |
while (angle<0) | |
angle += 360; | |
return angle; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment