Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 The-Gabo · Dec 16, 2012 at 03:14 PM · animationinputbuttonover

different animation same button

Hi, my character has got 2 hiting animations. When the player presses the attack button, play the first attack animation. When he presses a second time the attack button while the first animation is playing, play the second one. I have put a if statement in another. Maybe a boolean " isPlaying " is possible. What do you think ? Thank you.

 function Start () {
     
     animation.Stop();
     
     animation.wrapMode = WrapMode.Loop;
     
     var hit1 = animation["hit1"];
     hit1 = WrapMode.Once;
     hit1 = 1;
     
     var hit2 = animation["hit2"];
     hit2 = WrapMode.Once;
     hit2 = 2;
     
 }
     
 function Update () {
 
     
     if(Input.GetButtonDown("attack")) {
     
     animation.Play ("hit1");
     
         if(Input.GetButtonDown("attack")) {
             
             animation.Play ("hit2");
             
             
         }
     }

}

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
Best Answer

Answer by bompi88 · Dec 16, 2012 at 03:50 PM

Edit: Found a better way. I don't know if this is the best solution, but it works i think. Not tested though.

 var firstHit : boolean = true; // So the button is not pressed several times.
 var responseTime : float = 0.3F; // response time, so you don't doublehit even you don't hit twice
 var TimeOfDoubleHit : float = 2F; // For how long can you wait before hitting the button for the second time.
 var counter : int = 0;
 var hits = new Array ("hit1","hit2","hit3");
 
 function Update () {
 
        if(Input.GetKey(KeyCode.A)) {
           if (firstHit && counter < 3) {
                firstHit = false;
                animation.Play (hits[counter]);
                if (counter == 0) {
                    StartTimer();
                }    
             ResponseTime();
                counter++;
         }
     }
 }
 
 function ResponseTime() {
     yield WaitForSeconds(responseTime);
     firstHit = true;
 }
 
 function StartTimer() {
     yield WaitForSeconds(TimeOfDoubleHit);
     counter = 0;
 }
Comment
Add comment · Show 5 · 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 The-Gabo · Dec 16, 2012 at 06:10 PM 0
Share

Thanks this script works like a charm. But it is extremely complicated. And I would Actually like to add a third animation, you know, for a third attack. So I will try to understand it in order to make it possible. Thank you very much. I'm impressed. Apparently you have 666 karma. And that's funny.

avatar image idontwannawork The-Gabo · Jul 06, 2017 at 12:39 AM 0
Share

can I have a complete script or a complete project based on that 'same button but multiple animation' script? Please.

avatar image bompi88 · Dec 16, 2012 at 06:34 PM 0
Share

Found an easier way of implementing it. I edited my answer. hehe, yeah that actually was funny ;-)

avatar image The-Gabo · Dec 17, 2012 at 11:48 AM 0
Share

Thanks it works ! Way out of my league, though ^^. The response of the character is a little strange, i'll figure it out. I checked out you're games but none of them were out. When will they BE ?

avatar image bompi88 · Dec 17, 2012 at 01:07 PM 0
Share

I went back to school. Will get into them whenever I get some spare time ;)

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

11 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

Related Questions

GetButton Problem 1 Answer

Ensuring that a button is released before checking that it's pressed? 2 Answers

Unity 5 Controlling Animation with UI Button 0 Answers

Run Sprint animation and stop it when button is released 1 Answer

How to use Button as Cross Platform Input 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