Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Jun 20, 2016 at 10:07 AM by Vergil27.
avatar image
0
Question by Vergil27 · May 27, 2016 at 11:39 AM · c#buttonattackmore

How to make more combo attack,,

Need help, i want to make combo attack, but it just 2 attacking, but i need 4 attacking. this my script :

  if (Input.GetButtonDown("Fire1")) {
              if (!fired) {
                  fired = true;
                  timer = 0.0f;
                  comboCount = 0.0f;
                  animator.SetBool("Attack1", true); //this my attack1
                  Debug.Log("I served a punch!");
              } else 
              {
                  comboCount++;
                  if (comboCount == comboNum) 
                  {
                      animatio.SetBool("Attack2", true); //this my attack2, but i need more,,
                      Debug.Log("I did a combo!");              
                  }
                 // how i can to add more animation for attack, i need to make 2 more attack
              }
          }
  
          if (fired) 
          {
              timer += Time.deltaTime;
              if (timer > fireRate) 
              {
                  fired = false;
              }        
          }
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

  • Sort: 
avatar image
4
Best Answer

Answer by Hellium · May 27, 2016 at 11:40 AM

Here is a solution that will work. I think triggers will be more appropriate for your case. Take a look at the animator I created :

alt text

     public float fireRate = 2;
     
     public string[] comboParams ;
     private int comboIndex = 0 ;
     private Animator animator;
     private float resetTimer;

     void Awake()
     {
         if( comboParams == null || (comboParams != null && comboParams.length == 0)
             comboParams = new string[]{ "Attack1", "Attack2", "Attack3", "Attack4" };
         
         animator = GetComponent<Animator>() ;
     }

     void Update()
     {
         if ( Input.GetButtonDown( "Fire1" ) && comboIndex < comboParams.Length )
         {
             Debug.Log( comboParams[comboIndex] + " triggered" );
             animator.SetTrigger( comboParams[comboIndex] );
             
             // If combo must not loop
             comboIndex++;
             
             // If combo can loop
             // comboIndex = (comboIndex + 1) % comboParams.Length ;
             
             resetTimer = 0f;
         }

         // Reset combo if the user has not clicked quickly enough
         if ( comboIndex > 0 )
         {
             resetTimer += Time.deltaTime;
             if ( resetTimer > fireRate )
             {
                 animator.SetTrigger( "Reset" );
                 comboIndex = 0;
             }
         }
     }



animator.jpg (88.7 kB)
Comment
Add comment · Show 8 · 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
avatar image Vergil27 · May 27, 2016 at 02:33 PM 0
Share

the problem is : animationBools = new string[]{"Attack1", etc} the word of string is wrong, how i can fix it ??

avatar image Hellium Vergil27 · May 27, 2016 at 02:38 PM 0
Share

Try with this syntax :

animationBools = { "Attack1", "Attack2", "Attack3", "Attack4" } ;

avatar image Vergil27 Hellium · May 27, 2016 at 02:52 PM 0
Share

Still error at animationBools

avatar image Hellium · May 27, 2016 at 03:20 PM 0
Share

I have edited my answer to fix the compiler errors

avatar image Vergil27 Hellium · May 27, 2016 at 03:25 PM 0
Share

Sure,,,,,,

avatar image Hellium Vergil27 · May 27, 2016 at 04:45 PM 0
Share

@Vergil27 Answer edited again, and successfully tested ;)

Show more comments
avatar image voldok12 · May 30, 2017 at 08:20 AM 0
Share

i have a problem to error CS1525: Unexpected symbol `comboParams'. why this happen?

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

Colliding multiple enemys but only one at a time attacked 1 Answer

Making button start external .exe file HELP!!!! 1 Answer

CrossPlatformInput Detect Multiple Input Headache 1 Answer

Multiple mobile devices 0 Answers

How to stop and re-start audio? 1 Answer


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