RemoveRigidbody.cs 516 B

1234567891011121314151617181920212223
  1. using UnityEngine;
  2. // Removes a rigid body if it goes to sleep or falls
  3. // below a minimum vertical threshold.
  4. public class RemoveRigidbody : MonoBehaviour
  5. {
  6. public float minYPosition;
  7. void Update ()
  8. {
  9. if (transform.position.y < minYPosition)
  10. {
  11. Destroy(gameObject);
  12. }
  13. else
  14. {
  15. var rigidbody = GetComponent<Rigidbody>();
  16. if (rigidbody != null && rigidbody.IsSleeping())
  17. Destroy(gameObject);
  18. }
  19. }
  20. }