Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

240 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

CompareTag Between multiple Buttons 0 Answers

Turn Another UI image on and off with a Single UI Button 1 Answer

This is not possible to be called for standalone input. Please check your platform and code where this is called (C#) 2 Answers

Change mouse button click in existing code to ui button click.,Change the existing code from mouse click to ui buttons. 1 Answer

Click on two buttons one at a time to get an image 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges