This class provides additional functionality for working with Transform.
Available Methods
public static float Distance(this Transform from, Transform to)
This method returns distance between two transforms.
public static float DistanceXZ(this Transform from, Transform to)
This method returns 2D distance between two given 3D transforms (in XZ plane, ignoring Y).
public static void MoveTowards(this Transform t, Transform target, float speed)
This method moves transform towards certain transform with given speed.
public static void ResetTransform(this Transform t)
This method resets position, rotation and scale of given transform.
public static void LookAtIgnoreY(this Transform t, Transform target)
This method faces transform to the given transform, ignoring Y axis. It could be useful for top-down games.
Example:
turretTransform.LookAtIgnoreY(enemyTransform);
public static Transform FindDeepChild(this Transform parent, string name)
This method searches a child Transform by its name even if this child is deeply nested.
Example:
var chairTransform = houseTransform.FindDeepChild("Chair");
public static void SetUniformScale(this Transform t, float scale)
This method sets the same scale for all axes.
Example:
transform.SetUniformScale(2f);
public static bool IsVisibleFrom(this Transform t, Camera camera)
This method checks if given transform visible for certain camera.
Example:
if (transform.IsVisibleFrom(Camera.main))
{
//Do some logics if this transform is visible from main camera...
}
public static void DestroyAllChildren(this Transform t)
This method destroys all nested children of given transform.
Example:
rewardsTransform.DestroyAllChildren(); //Clear rewards UI slots