using System; using Sonigon; using UnityEngine; public class DestructibleBoxDestruction : MonoBehaviour { public bool soundPlayDestruction; public SoundEvent soundBoxDestruction; private void Start() { DamagableEvent componentInParent = GetComponentInParent(); componentInParent.DieAction = (Action)Delegate.Combine(componentInParent.DieAction, new Action(Die)); } private void Die(Vector2 dmg) { if (soundPlayDestruction) { SoundManager.Instance.PlayAtPosition(soundBoxDestruction, SoundManager.Instance.GetTransform(), base.transform); } Rigidbody2D[] componentsInChildren = GetComponentsInChildren(includeInactive: true); for (int i = 0; i < componentsInChildren.Length; i++) { if (base.transform != componentsInChildren[i].transform) { componentsInChildren[i].transform.SetParent(base.transform.root); componentsInChildren[i].transform.gameObject.SetActive(value: true); componentsInChildren[i].AddForce(dmg * UnityEngine.Random.Range(0f, 1f) * 500f, ForceMode2D.Impulse); componentsInChildren[i].AddTorque(UnityEngine.Random.Range(-1f, 1f) * 1000f, ForceMode2D.Impulse); componentsInChildren[i].GetComponent().seconds = UnityEngine.Random.Range(0f, 0.5f); componentsInChildren[i].GetComponentInChildren().Start(); componentsInChildren[i].GetComponentInChildren().timeAmount *= UnityEngine.Random.Range(0.5f, 2f); componentsInChildren[i].GetComponentInChildren().DoBlink(); componentsInChildren[i].gameObject.layer = 18; } } } }