/
KasatkinGV
/
CourseWork
Обзор
Документация
Войти
/
KasatkinGV
/
CourseWork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PlayerAttack.cs
94 строки
2 KB
KasatkinGV
upload files
11 июн 2025, 01:06
11 июн 2025, 01:06
3efd0d1
Код
Авторство
О чём код?
using UnityEngine; using System.Collections; public class PlayerAttack : MonoBehaviour { private Animator animator; private PlayerHealth playerHealth; private float[] attackDurations = { 0.5f, 0.5f, 0.7f }; private float inputBufferWindow = 0.6f; private float minBufferTime = 0.1f; private int comboState = 0; private bool isAttacking = false; private bool attackBuffered = false; public bool IsAttacking => isAttacking; private bool IsHurted => playerHealth.IsHurted; private void Awake() { animator = GetComponent<Animator>(); playerHealth = GetComponent<PlayerHealth>(); } private void Update() { if (PauseMenuController.IsPaused) return; if (Input.GetMouseButtonDown(0) && !IsHurted) { if (isAttacking) attackBuffered = true; else StartCoroutine(ComboAttackSequence()); } } private IEnumerator ComboAttackSequence() { isAttacking = true; comboState = 1; while (comboState <= attackDurations.Length) { attackBuffered = false; animator.SetInteger("ComboState", comboState); float attackTime = attackDurations[comboState - 1]; float bufferStart = attackTime * minBufferTime; float bufferEnd = attackTime * inputBufferWindow; float timer = 0f; bool bufferedThisAttack = false; while (timer < attackTime) { timer += Time.deltaTime; if (!bufferedThisAttack && timer >= bufferStart && timer <= bufferEnd && Input.GetMouseButtonDown(0)) { attackBuffered = true; bufferedThisAttack = true; } yield return null; } if (attackBuffered) comboState++; else break; } ResetCombo(); isAttacking = false; } public void CancelAttack() { StopAllCoroutines(); ResetCombo(); isAttacking = false; attackBuffered = false; } private void ResetCombo() { comboState = 0; animator.SetInteger("ComboState", 0); } }