diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/Destructible.cs |
+ init
Diffstat (limited to 'GameCode/Destructible.cs')
-rw-r--r-- | GameCode/Destructible.cs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/GameCode/Destructible.cs b/GameCode/Destructible.cs new file mode 100644 index 0000000..e2b71b0 --- /dev/null +++ b/GameCode/Destructible.cs @@ -0,0 +1,45 @@ +using System; +using UnityEngine; + +public class Destructible : Damagable +{ + public float threshold = 25f; + + public float force = 1f; + + public float rangeMulti = 1f; + + public override void CallTakeDamage(Vector2 damage, Vector2 damagePosition, GameObject damagingWeapon = null, Player damagingPlayer = null, bool lethal = true) + { + throw new NotImplementedException(); + } + + public override void TakeDamage(Vector2 damage, Vector2 position, GameObject damagingWeapon = null, Player damagingPlayer = null, bool lethal = true, bool ignoreBlock = false) + { + if (!(damage.magnitude < threshold)) + { + damage = damage.normalized * 100f; + Transform[] array = new Transform[base.transform.childCount]; + for (int i = 0; i < array.Length; i++) + { + array[i] = base.transform.GetChild(i); + } + foreach (Transform transform in array) + { + transform.gameObject.SetActive(value: true); + transform.SetParent(null, worldPositionStays: true); + float num = damage.magnitude * 0.02f * rangeMulti; + float num2 = Mathf.Clamp((num - Vector2.Distance(transform.position, position)) / num, 0f, 1f); + Rigidbody2D component = transform.GetComponent<Rigidbody2D>(); + component.AddForce(damage * num2 * force * 0.1f * component.mass, ForceMode2D.Impulse); + transform.gameObject.AddComponent<RemoveAfterSeconds>().seconds = UnityEngine.Random.Range(1f, 3f); + } + base.gameObject.SetActive(value: false); + } + } + + public override void TakeDamage(Vector2 damage, Vector2 damagePosition, Color dmgColor, GameObject damagingWeapon = null, Player damagingPlayer = null, bool lethal = true, bool ignoreBlock = false) + { + TakeDamage(damage, damagePosition, dmgColor, damagingWeapon, damagingPlayer, lethal); + } +} |