Description
The Rigidbody
property of the Collider
class provides access to the Rigidbody
component that the collider is attached to, if any. This property is useful for determining whether the collider is part of a dynamic physics object. If the property returns null
, it typically indicates that the collider is static, part of world geometry, or a keyframe.
Usage
To access the Rigidbody
property, you need to have a reference to a Collider
instance. You can then check if the collider is part of a Rigidbody
by accessing this property. If the property is null
, the collider is not associated with a Rigidbody
.
Example
// Example of accessing the Rigidbody property
Collider collider = someGameObject.GetComponent<Collider>();
Rigidbody attachedRigidbody = collider.Rigidbody;
if (attachedRigidbody != null)
{
// The collider is part of a Rigidbody
// You can now manipulate the Rigidbody as needed
}
else
{
// The collider is static or part of world geometry
}