Advertisement
GoodNoodle

Weapon Combo

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