Init
This commit is contained in:
26
Assets/ThirdParty/DestroyIt/Scripts/Runtime/Behaviors/DestructibleParent.cs
vendored
Normal file
26
Assets/ThirdParty/DestroyIt/Scripts/Runtime/Behaviors/DestructibleParent.cs
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace DestroyIt
|
||||
{
|
||||
/// <summary>
|
||||
/// Place this script on a rigidbody parent that has one or more compound collider Destructible children under it.
|
||||
/// Example: the SUV in the showcase demo scene. It is a rigidbody parent but not Destructible itself. But it has many child colliders that are destructible objects.
|
||||
/// </summary>
|
||||
public class DestructibleParent : MonoBehaviour
|
||||
{
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.contacts.Length == 0) return;
|
||||
|
||||
Destructible destructibleObj = collision.contacts[0].thisCollider.gameObject.GetComponentInParent<Destructible>();
|
||||
if (destructibleObj != null)
|
||||
{
|
||||
Rigidbody otherRbody = collision.contacts[0].otherCollider.attachedRigidbody;
|
||||
if (otherRbody != null)
|
||||
destructibleObj.ProcessDestructibleCollision(collision, otherRbody);
|
||||
else
|
||||
destructibleObj.ProcessDestructibleCollision(collision, this.GetComponent<Rigidbody>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user