Description
The Sleeping
property of the Rigidbody
class indicates whether the rigid body is currently in a sleeping state. A sleeping rigid body is one that is not actively participating in the physics simulation, typically because it is at rest and not subject to any forces or collisions. This property is read-only and cannot be modified directly.
Usage
Use the Sleeping
property to check if a Rigidbody
is currently inactive in the physics simulation. This can be useful for optimizing performance by avoiding unnecessary calculations for objects that are not moving.
Example
// Example of checking if a Rigidbody is sleeping
Rigidbody myRigidbody = new Rigidbody();
if (myRigidbody.Sleeping)
{
// Perform actions knowing the rigid body is at rest
// For example, you might want to wake it up by applying a force
Vector3 force = new Vector3(0, 10, 0);
myRigidbody.ApplyForce(ref force);
}