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/TasteOfBlood.cs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 GameCode/TasteOfBlood.cs (limited to 'GameCode/TasteOfBlood.cs') diff --git a/GameCode/TasteOfBlood.cs b/GameCode/TasteOfBlood.cs new file mode 100644 index 0000000..1a7ed41 --- /dev/null +++ b/GameCode/TasteOfBlood.cs @@ -0,0 +1,66 @@ +using System; +using UnityEngine; + +public class TasteOfBlood : MonoBehaviour +{ + public AnimationCurve attackSpeedCurve; + + public float decaySpeed = 1f; + + private float damageValue; + + private CharacterStatModifiers stats; + + private ParticleSystem part; + + private CharacterData data; + + private bool isOn; + + private void Start() + { + part = GetComponentInChildren(); + stats = GetComponentInParent(); + CharacterStatModifiers characterStatModifiers = stats; + characterStatModifiers.DealtDamageAction = (Action)Delegate.Combine(characterStatModifiers.DealtDamageAction, new Action(DealtDamage)); + data = GetComponentInParent(); + } + + public void DealtDamage(Vector2 damage, bool selfDamage) + { + if (!selfDamage) + { + damageValue += damage.magnitude; + } + damageValue = Mathf.Clamp(damageValue, 0f, 50f); + } + + private void Update() + { + if (!data.isPlaying) + { + damageValue = 0f; + } + if (damageValue > 0f) + { + damageValue -= TimeHandler.deltaTime * decaySpeed; + isOn = true; + } + else + { + isOn = false; + } + if (damageValue > 10f) + { + if (!part.isPlaying) + { + part.Play(); + } + } + else if (part.isPlaying) + { + part.Stop(); + } + stats.tasteOfBloodSpeed = attackSpeedCurve.Evaluate(damageValue); + } +} -- cgit v1.1-26-g67d0