- Home /
 
 
               Question by 
               F4LL_Legion_Dev · Jun 30, 2020 at 05:36 AM · 
                uiscript.buttonscombo  
              
 
              How to convert a Mouse Input Combo System to Button?
Hi, I have a combo system from Colenderp's video. I was wondering how I'd convert it from inputs to UI Button inputs? So instead of clicking inputs on the mouse, i want to click a button. Here is the video: https://www.youtube.com/watch?v=JV-PjU4q2EE
Here is the code:
 using System.Collections;
 using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using UnityEngine;
 using UnityEngine.Events;
 using UnityEngine.UI;
 
 public enum AttackType {  heavy = 0, light = 1};
 public class fightingCombo : MonoBehaviour
 {
     [Header("Attacks")]
     public Attack heavyAttack;
     public Attack lightAttack;
     public List<Combo> combos;
     public float comboLeeway = 0.25f;
 
     Attack curAttack = null;
     ComboInput lastInput = null;
     List<int> currentCombos = new List<int>();
     float timer = 0;
     float leeway = 0;
     bool skip = false;
 
     void PrimeCombos()
     {
         for (int i = 0; i < combos.Count; i++)
         {
             Combo c = combos[i];
             c.onInputted.AddListener(() =>
             {
                 //call funtion for combos attack
                 skip = true;
                 Attack(c.comboAttack);
                 ResetCombos();
             });
         }
     }
 
     void Update()
     {
         if (curAttack != null)
         {
             if (timer > 0)
             {
                 timer -= Time.deltaTime;
             }
             else
             {
                 curAttack = null;
             }
             return;
         }
 
         if (currentCombos.Count > 0)
         {
             leeway += Time.deltaTime;
             if (leeway >= comboLeeway)
             {
                 if (lastInput != null)
                 {
                     Attack(getAttackFromType(lastInput.type));
                     lastInput = null;
                 }
                 ResetCombos();
             }
         }
         else
         {
             leeway = 0;
         }
 
         ComboInput input = null;
         if (Input.GetMouseButtonDown(1))
             input = new ComboInput(AttackType.heavy);
         if (Input.GetMouseButtonDown(0))
             input = new ComboInput(AttackType.light);
 
         if (input == null) return;
         lastInput = input;
 
         List<int> remove = new List<int>();
         for (int i = 0; i < currentCombos.Count; i++)
         {
             Combo c = combos[currentCombos[i]];
             if (c.continueCombo(input))
                 leeway = 0;
             else
             {
                 remove.Add(i);
             }
         }
 
         if (skip)
         {
             skip = false;
             return;
         }
 
         for(int i = 0; i < combos.Count; i++)
         {
             if (currentCombos.Contains(i)) continue;
             if (combos[i].continueCombo(input))
             {
                 currentCombos.Add(i);
                 leeway = 0;
             }
                 
         }
 
         foreach (int i in remove)
             currentCombos.RemoveAt(i);
         if (currentCombos.Count <= 0)
             Attack(getAttackFromType(input.type));
     }
 
     void ResetCombos()
     {
         leeway += Time.deltaTime;
         for (int i = 0; i < currentCombos.Count; i++)
         {
             Combo c = combos[currentCombos[i]];
             c.ResetCombo();
         }
 
         currentCombos.Clear();
     }
     
     void Attack(Attack att)
     {
         curAttack = att;
         timer = att.length;
     }
 
     Attack getAttackFromType(AttackType t)
     {
         if (t == AttackType.heavy)
             return heavyAttack;
         if (t == AttackType.light)
             return lightAttack;
         return null;
     }
 
 }
 
 [System.Serializable]
 public class Attack
 {
     public string name;
     public float length;
 }
 
 [System.Serializable] 
 public class ComboInput
 {
     public AttackType type;
 
     public ComboInput(AttackType t)
     {
         type = t;
     }
 
     public bool isSameAs(ComboInput test)
     {
         return (type == test.type);
     }
 }
 
 [System.Serializable] 
 public class Combo
 {
     public List<ComboInput> inputs;
     public Attack comboAttack;
     public UnityEvent onInputted;
     int curInput = 0;
 
     public bool continueCombo(ComboInput i)
     {
         if(inputs[curInput].isSameAs(i))
         {
             curInput++;
             if(curInput >= inputs.Count) //finished inputs and shld do attack
             {
                 onInputted.Invoke();
                 curInput = 0;
             }
             return true;
         }
         else
         {
             curInput = 0;
             return false;
         }
     }
 
     public ComboInput currentComboInput()
     {
         if (curInput >= inputs.Count) return null;
         return inputs[curInput];
     }
 
     public void ResetCombo()
     {
         curInput = 0;
     }
 }
 
               Sorry for the long code, but ive been looking into this for a while now, with no help. Any help would be very greatly appreciated.
               Comment
              
 
               
              Answer by BenWiller1989 · Aug 15, 2020 at 01:56 PM
Well, why should it be a problem, to have a reference of a method from this script on a UI Button, changing a Variable (a bool perhaps) to indicate the Input on the UI Button for your Script? I don't understand your issue.... You know how UI buttons work right? Br
Your answer