This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
Followers 0
lucian112

Animation

Question

Posted (edited)

Hello,i have a simple question. How to play animation gun on press button? like fire ,reload animation?I made animations!

Edited by lucian112

Share this post


Link to post
Share on other sites

3 answers to this question

  • 1

Posted (edited)

Please login or register to see this code.

Make sure that you have your animations marked as legacy, if you don't this script will not work. In the above example I made it so that if the player presses the key "r" the reload animation will be played. Obviously you will replace "Animation Name" with your actual animation's name.

Edited by omard2000
Added information
1 person likes this

Share this post


Link to post
Share on other sites
  • 0

Posted (edited)

If you want to use animator style animation shooting you could make a new animation controller, attach the controller to your player, then from idle state make a connection with for example boolean parameter state that connects to shooting animation clip.

And from code:
 

Please login or register to see this code.

PS! i  just quickly wrote a example script, this might not be correct, i will double check it after i get home from work.

What this script does exactly is, is that it transmits the parameter value to animator and the animator does the rest, plays the clip.

I highly suggest you take a look at this brief unity offical tutorial: (trust me you will thank me later)
Please login or register to see this link.

 

 

Why i'm suggesting this method of shooting, is since legacy should stay legacy, you could expand easier with the animator system etc i will let others give you advice, why animator is better or what not.
 

Edited by Andrus99
1 person likes this

Share this post


Link to post
Share on other sites
  • 0

If your animation may not play at first for some reason, in the inspector(on the rectangle with the "Inspector" text) right click and select debug. Next, check is Legacy animation, as I remember this was a big issue for my first few tests as I had no idea wtf was going on.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0