using RayFire; using Sirenix.OdinInspector; using UnityEngine; // ReSharper disable once CheckNamespace namespace BlueWaterProject { public class DestructiveObject : MonoBehaviour { [Title("초기화 방식")] [SerializeField] private bool autoInit = true; [Title("기본 설정")] [field: SerializeField] public int Strength { get; private set; } = 100; [SerializeField] private float power = 10f; [SerializeField] private float damageCooldown = 2f; [SerializeField] private bool isHitting; [SerializeField] private RayfireRigid rayfire; [SerializeField] private Rigidbody rb; [Button("셋팅 초기화")] private void Init() { rayfire = GetComponent(); } private void Awake() { if (autoInit) { Init(); } } private void Start() { rb = GetComponent(); rb.isKinematic = true; } private void OnCollisionEnter(Collision other) { if (other.collider.CompareTag("ShipPlayer")) { var iDestructible = other.collider.GetComponent(); var otherStrength = iDestructible.Strength; if (otherStrength > Strength) { DestroyObject(); } else if (otherStrength < Strength) { if (isHitting) return; Hit(iDestructible); } else { DestroyObject(); Hit(iDestructible); } } else if (other.collider.CompareTag("Missile")) { DestroyObject(); } } private void DestroyObject() { rb.isKinematic = false; rayfire.Demolish(); } private void Hit(IDestructible iDestructible) { isHitting = true; iDestructible.TakeDamage(power); if (!gameObject.activeSelf) return; StartCoroutine(Utils.CoolDown(damageCooldown, () => isHitting = false)); } } }