GameObject Extensions
Get Or Add Component
This retrieves an existing component of type T or adds it if it doesn't exist.
GameObject myObject = new GameObject();
Rigidbody rb = myObject.GetOrAddComponent<Rigidbody>();Reset Transform
This resets the transform of a GameObject to zero position, no rotation, and a scale of one.
Transform myTransform = myObject.transform;
myTransform.ResetTransform();Is Grounded
This checks if the GameObject is grounded using a raycast.
bool grounded = myObject.Grounded(0.1f, LayerMask.GetMask("Ground"));Add Force Towards
This applies force to a Rigidbody in the direction of another GameObject.
Rigidbody rb = myObject.GetComponent<Rigidbody>();
rb.AddForceTowards(target, 10f);Set Velocity Towards
This sets the Rigidbody's velocity towards a specified target position at a given speed.
Get Closest
This method is especially useful in situations like AI targeting, where you need to find the nearest point of interest (enemies, items, etc.) to a specific GameObject.
Is Visible To Camera
This checks whether the GameObject is currently visible by any camera.
Set Layer
This sets the layer of a GameObject using its name.
Has Layer
This checks if a GameObject's layer matches a specified layer name.
Set Tag
This sets the tag of a GameObject.
Has Tag
This checks if a GameObject's tag matches a specified tag name.
Add Child
This adds a child GameObject to a parent GameObject.
Clear Children
This removes all child GameObjects from a parent GameObject.
Get Child By Name
This retrieves a child GameObject by its name.
Get Child By Tag
This retrieves a child GameObject by its tag.
Last updated