Skip to content

Instantly share code, notes, and snippets.

@brunomikoski
Last active December 26, 2015 05:09
Show Gist options
  • Save brunomikoski/7098783 to your computer and use it in GitHub Desktop.
Save brunomikoski/7098783 to your computer and use it in GitHub Desktop.
How to search for a gameobject inside another hierarchy.
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