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/DamageBox.cs |
+ init
Diffstat (limited to 'GameCode/DamageBox.cs')
-rw-r--r-- | GameCode/DamageBox.cs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/GameCode/DamageBox.cs b/GameCode/DamageBox.cs new file mode 100644 index 0000000..e86d79f --- /dev/null +++ b/GameCode/DamageBox.cs @@ -0,0 +1,96 @@ +using Sonigon; +using UnityEngine; + +public class DamageBox : MonoBehaviour +{ + [Header("Sound")] + public bool soundPlaySawDamage; + + public SoundEvent soundSawDamage; + + [Header("Settings")] + public bool towardsCenterOfMap; + + public bool awayFromMe; + + public float damage = 25f; + + public float force; + + public float setFlyingFor; + + public float shake; + + public float cd = 0.3f; + + public bool ignoreBlock; + + public ParticleSystem dmgPart; + + private float time; + + private SpawnedAttack spawned; + + private void Start() + { + spawned = GetComponentInParent<SpawnedAttack>(); + } + + private void OnCollisionEnter2D(Collision2D collision) + { + Collide(collision); + } + + private void OnCollisionStay2D(Collision2D collision) + { + Collide(collision); + } + + private void Collide(Collision2D collision) + { + if (Time.time < time + cd) + { + return; + } + Vector3 vector = base.transform.root.forward; + if (towardsCenterOfMap) + { + vector = -collision.contacts[0].point.normalized; + } + if (awayFromMe) + { + vector = (collision.transform.position - base.transform.position).normalized; + } + Damagable componentInParent = collision.transform.GetComponentInParent<Damagable>(); + if (!componentInParent) + { + return; + } + time = Time.time; + HealthHandler component = componentInParent.GetComponent<HealthHandler>(); + CharacterData component2 = component.GetComponent<CharacterData>(); + if (!component2 || component2.view.IsMine) + { + if ((bool)component) + { + component.CallTakeForce(vector * force, ForceMode2D.Impulse, forceIgnoreMass: false, ignoreBlock, setFlyingFor); + } + componentInParent.CallTakeDamage(damage * vector, base.transform.position, null, (spawned != null) ? spawned.spawner : null); + if (soundPlaySawDamage) + { + SoundManager.Instance.PlayAtPosition(soundSawDamage, SoundManager.Instance.GetTransform(), base.transform); + } + if ((bool)dmgPart) + { + Vector3 forward = vector; + vector.z = 0f; + dmgPart.transform.parent.rotation = Quaternion.LookRotation(forward); + dmgPart.Play(); + } + if (shake != 0f) + { + component2.player.Call_AllGameFeel(shake * (Vector2)vector); + } + } + } +} |