summaryrefslogtreecommitdiff
path: root/GameCode/DestructibleBoxDestruction.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/DestructibleBoxDestruction.cs
+ init
Diffstat (limited to 'GameCode/DestructibleBoxDestruction.cs')
-rw-r--r--GameCode/DestructibleBoxDestruction.cs40
1 files changed, 40 insertions, 0 deletions
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<DamagableEvent>();
+ componentInParent.DieAction = (Action<Vector2>)Delegate.Combine(componentInParent.DieAction, new Action<Vector2>(Die));
+ }
+
+ private void Die(Vector2 dmg)
+ {
+ if (soundPlayDestruction)
+ {
+ SoundManager.Instance.PlayAtPosition(soundBoxDestruction, SoundManager.Instance.GetTransform(), base.transform);
+ }
+ Rigidbody2D[] componentsInChildren = GetComponentsInChildren<Rigidbody2D>(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<RemoveAfterSeconds>().seconds = UnityEngine.Random.Range(0f, 0.5f);
+ componentsInChildren[i].GetComponentInChildren<GetColor>().Start();
+ componentsInChildren[i].GetComponentInChildren<ColorBlink>().timeAmount *= UnityEngine.Random.Range(0.5f, 2f);
+ componentsInChildren[i].GetComponentInChildren<ColorBlink>().DoBlink();
+ componentsInChildren[i].gameObject.layer = 18;
+ }
+ }
+ }
+}