Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Combo chain script

Discussion in 'Scripting' started by BadWolfy77, Feb 21, 2020.

  1. BadWolfy77

    BadWolfy77

    Joined:
    Jan 5, 2020
    Posts:
    3
    Hello everybody, got a problem with this script. When I click too fast the button it skips straight to the 3rd animation and afterwards returns to the 2nd to finish the cycle shouldn't the line

    if (current_Combo_State == ComboState.Step3)
    return;

    prevent any issue like this one?
    I tried everything: adding && current_Combo_State == ComboState.Step2; make the animation almost the same time of the private float default_Combo_Timer = 0.3f; inverting step 3 and step 2 (but if I do that, i end up playing step 1, step 3, step 2 if I press the button slower).
    Code (CSharp):
    1. public enum ComboState
    2. {
    3.     NONE,
    4.     Step1,
    5.     Step2,
    6.     Step3
    7. }
    8. public class AttackCombo : MonoBehaviour
    9. {
    10.     private Animator anim;
    11.  
    12.     private bool activateTimerToReset;
    13.  
    14.     private float default_Combo_Timer = 0.3f;
    15.  
    16.     private float current_Combo_Timer;
    17.  
    18.     private ComboState current_Combo_State;
    19.  
    20.     void Awake()
    21.     {
    22.         anim = GetComponent<Animator>();
    23.     }
    24.     // Start is called before the first frame update
    25.     void Start()
    26.     {
    27.         current_Combo_Timer = default_Combo_Timer;
    28.         current_Combo_State = ComboState.NONE;
    29.     }
    30.  
    31.     // Update is called once per frame
    32.     void Update()
    33.     {
    34.         ComboAttacks();
    35.         ResetComboState();
    36.     }
    37.  
    38.     void ComboAttacks()
    39.     {
    40.         if (Input.GetKeyDown(KeyCode.I))
    41.         {
    42.             if (current_Combo_State == ComboState.Step3)
    43.                 return;
    44.  
    45.             current_Combo_State++;
    46.             activateTimerToReset = true;
    47.             current_Combo_Timer = default_Combo_Timer;
    48.      
    49.  
    50.         if(current_Combo_State == ComboState.Step1)
    51.         {
    52.             anim.SetTrigger("Slash1");
    53.         }
    54.  
    55.         if (current_Combo_State == ComboState.Step2)
    56.         {
    57.             anim.SetTrigger("360");
    58.         }
    59.  
    60.         if (current_Combo_State == ComboState.Step3)
    61.         {
    62.             anim.SetTrigger("GSS3");
    63.         }
    64.         }
    65.     }
    66.  
    67.     void ResetComboState()
    68.     {
    69.         if (activateTimerToReset)
    70.         {
    71.             current_Combo_Timer -= Time.deltaTime;
    72.  
    73.             if(current_Combo_Timer <= 0f)
    74.             {
    75.                 current_Combo_State = ComboState.NONE;
    76.  
    77.                 activateTimerToReset = false;
    78.                 current_Combo_Timer = default_Combo_Timer;
    79.             }
    80.         }
    81.     }
     
    Last edited: Feb 22, 2020
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
  3. BadWolfy77

    BadWolfy77

    Joined:
    Jan 5, 2020
    Posts:
    3