Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public enum ComboState
- {
- none,
- attack1,
- attack2,
- attack3,
- heavtAttack1,
- heavyAttack2
- }
- public class PlayerCombo : MonoBehaviour
- {
- AnimManager animManager;
- private bool comboResetTimer;
- private float defultComboTimer = 0.4f;
- private float currentComboTimer;
- private ComboState currentComboState;
- // Start is called before the first frame update
- private void Awake()
- {
- animManager = GetComponentInChildren<AnimManager>();
- }
- void Start()
- {
- currentComboTimer = defultComboTimer;
- currentComboState = ComboState.none;
- }
- // Update is called once per frame
- void Update()
- {
- ComboAttacks();
- ResetComboState();
- }
- void ComboAttacks()
- {
- if(Input.GetKeyDown(KeyCode.R))
- {
- if (currentComboState == ComboState.attack3 ||
- currentComboState == ComboState.heavtAttack1 ||
- currentComboState == ComboState.heavyAttack2)
- return;
- currentComboState++;
- comboResetTimer = true;
- currentComboTimer = defultComboTimer;
- if(currentComboState == ComboState.attack1 )
- {
- animManager.attack1();
- if (currentComboState == ComboState.attack2)
- {
- animManager.attack2();
- }
- if (currentComboState == ComboState.attack3)
- {
- animManager.attack3();
- }
- }
- }
- // if light attack
- if (Input.GetKeyDown(KeyCode.T))
- {
- if (currentComboState == ComboState.attack3 ||
- currentComboState == ComboState.heavyAttack2)
- return;
- if(currentComboState == ComboState.none ||
- currentComboState == ComboState.attack1||
- currentComboState == ComboState.attack2)
- {
- currentComboState = ComboState.heavtAttack1;
- } else if (currentComboState == ComboState.heavtAttack1)
- {
- currentComboState++;
- }
- comboResetTimer = true;
- currentComboTimer = defultComboTimer;
- if(currentComboState == ComboState.heavtAttack1)
- {
- animManager.HeavyAttack1();
- }
- if (currentComboState == ComboState.heavyAttack2)
- {
- animManager.HeavyAttack2();
- }
- }
- }
- void ResetComboState()
- {
- if(comboResetTimer)
- {
- currentComboTimer -= Time.deltaTime;
- if(currentComboTimer <= 0)
- {
- currentComboState = ComboState.none;
- comboResetTimer = false;
- currentComboTimer = defultComboTimer;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement