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/StunHandler.cs |
+ init
Diffstat (limited to 'GameCode/StunHandler.cs')
-rw-r--r-- | GameCode/StunHandler.cs | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/GameCode/StunHandler.cs b/GameCode/StunHandler.cs new file mode 100644 index 0000000..bb3f93e --- /dev/null +++ b/GameCode/StunHandler.cs @@ -0,0 +1,102 @@ +using Sonigon; +using UnityEngine; + +public class StunHandler : MonoBehaviour +{ + [Header("Sounds")] + public SoundEvent soundCharacterStunLoop; + + private bool soundStunIsPlaying; + + [Header("Settings")] + public CodeAnimation codeAnim; + + private Player player; + + private CharacterData data; + + private void Start() + { + player = GetComponent<Player>(); + data = player.data; + } + + private void Update() + { + if (data.stunTime > 0f) + { + data.stunTime -= TimeHandler.deltaTime; + data.sinceGrounded = 0f; + if (!data.isStunned) + { + StartStun(); + } + } + else if (data.isStunned) + { + StopStun(); + } + if (data.isStunned && data.isPlaying && !data.dead) + { + if (!soundStunIsPlaying) + { + soundStunIsPlaying = true; + SoundManager.Instance.Play(soundCharacterStunLoop, base.transform); + } + } + else if (soundStunIsPlaying) + { + soundStunIsPlaying = false; + SoundManager.Instance.Stop(soundCharacterStunLoop, base.transform); + } + } + + private void StartStun() + { + player.data.playerVel.velocity *= 0f; + player.data.playerVel.isKinematic = true; + player.data.input.stunnedInput = true; + codeAnim.PlayIn(); + data.isStunned = true; + } + + public void StopStun() + { + player.data.playerVel.isKinematic = false; + player.data.input.stunnedInput = false; + if (codeAnim.currentState == CodeAnimationInstance.AnimationUse.In) + { + codeAnim.PlayOut(); + } + data.isStunned = false; + data.stunTime = 0f; + } + + private void OnDisable() + { + codeAnim.transform.localScale = Vector3.zero; + soundStunIsPlaying = false; + SoundManager.Instance.Stop(soundCharacterStunLoop, base.transform); + } + + private void OnDestroy() + { + soundStunIsPlaying = false; + SoundManager.Instance.Stop(soundCharacterStunLoop, base.transform); + } + + public void AddStun(float f) + { + if (!data.block.IsBlocking()) + { + if (f > data.stunTime) + { + data.stunTime = f; + } + if (!data.isStunned) + { + StartStun(); + } + } + } +} |