Files
BlueArchiveMiniGame/Assets/ThirdParty/DestroyIt/Scripts/Runtime/Behaviors/DestructibleParent.cs

26 lines
1.1 KiB
C#
Raw Normal View History

2025-09-17 18:56:28 +08:00
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>());
}
}
}
}