Advertisement
GoodNoodle

Player Combo

Jun 2nd, 2021
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5.  
  6. public enum ComboState
  7. {
  8.     none,
  9.     attack1,
  10.     attack2,
  11.     attack3,
  12.     heavtAttack1,
  13.     heavyAttack2
  14. }
  15. public class PlayerCombo : MonoBehaviour
  16. {
  17.     AnimManager animManager;
  18.  
  19.     private bool comboResetTimer;
  20.  
  21.     private float defultComboTimer = 0.4f;
  22.  
  23.     private float currentComboTimer;
  24.  
  25.     private ComboState currentComboState;
  26.     // Start is called before the first frame update
  27.  
  28.     private void Awake()
  29.     {
  30.         animManager = GetComponentInChildren<AnimManager>();
  31.     }
  32.     void Start()
  33.     {
  34.         currentComboTimer = defultComboTimer;
  35.         currentComboState = ComboState.none;
  36.     }
  37.     // Update is called once per frame
  38.     void Update()
  39.     {
  40.         ComboAttacks();
  41.         ResetComboState();
  42.     }
  43.     void ComboAttacks()
  44.         {
  45.         if(Input.GetKeyDown(KeyCode.R))
  46.         {
  47.             if (currentComboState == ComboState.attack3 ||
  48.                currentComboState == ComboState.heavtAttack1 ||
  49.                currentComboState == ComboState.heavyAttack2)
  50.                 return;
  51.            
  52.  
  53.            
  54.             currentComboState++;
  55.             comboResetTimer = true;
  56.             currentComboTimer = defultComboTimer;
  57.  
  58.             if(currentComboState == ComboState.attack1 )
  59.             {
  60.                 animManager.attack1();
  61.  
  62.  
  63.                 if (currentComboState == ComboState.attack2)
  64.                 {
  65.                     animManager.attack2();
  66.                 }
  67.  
  68.  
  69.                 if (currentComboState == ComboState.attack3)
  70.                 {
  71.                     animManager.attack3();
  72.                 }
  73.             }
  74.         }
  75.         // if light attack
  76.         if (Input.GetKeyDown(KeyCode.T))
  77.         {
  78.             if (currentComboState == ComboState.attack3 ||
  79.                 currentComboState == ComboState.heavyAttack2)
  80.                 return;
  81.            
  82.             if(currentComboState == ComboState.none ||
  83.                 currentComboState == ComboState.attack1||
  84.                 currentComboState == ComboState.attack2)
  85.             {
  86.                 currentComboState = ComboState.heavtAttack1;
  87.             } else if (currentComboState == ComboState.heavtAttack1)
  88.             {
  89.                 currentComboState++;
  90.             }
  91.             comboResetTimer = true;
  92.             currentComboTimer = defultComboTimer;
  93.  
  94.             if(currentComboState == ComboState.heavtAttack1)
  95.             {
  96.                 animManager.HeavyAttack1();
  97.             }
  98.  
  99.             if (currentComboState == ComboState.heavyAttack2)
  100.             {
  101.                 animManager.HeavyAttack2();
  102.             }
  103.         }
  104.     }    
  105.     void ResetComboState()
  106.     {
  107.         if(comboResetTimer)
  108.         {
  109.             currentComboTimer -= Time.deltaTime;
  110.  
  111.             if(currentComboTimer <= 0)
  112.             {
  113.                 currentComboState = ComboState.none;
  114.  
  115.                 comboResetTimer = false;
  116.                 currentComboTimer = defultComboTimer;
  117.             }
  118.         }
  119.     }
  120. }
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement