From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/DestructibleBoxDestruction.cs | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 GameCode/DestructibleBoxDestruction.cs (limited to 'GameCode/DestructibleBoxDestruction.cs') diff --git a/GameCode/DestructibleBoxDestruction.cs b/GameCode/DestructibleBoxDestruction.cs new file mode 100644 index 0000000..d7f7fb8 --- /dev/null +++ b/GameCode/DestructibleBoxDestruction.cs @@ -0,0 +1,40 @@ +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; + } + } + } +} -- cgit v1.1-26-g67d0