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 /
avatar image
1
Question by TheDarkRager · Mar 02, 2016 at 01:12 PM · animationscripting problemaimreverseaimdownsights

How do I make an animation play once forward while holding down a button/key and then play the same animation backwards when I let go of that button?

In this case the animation I want to have played is aiming for my FPS. I've got the aiming down pat but when I let go of the key it just stays there aiming still. This is what my code looks like right now...

fuction Update() {

  If(input.getbuttondown("fire2")) {
       Getcomponent.<Animation>().Play("aim"); }

Then under it I have another script for aim and shoot...

  If(input.getkeydown("fire2"));
       If(input.getkeydown("fire1")) {
            Getcomponent.<Animation>().Play("aimandshoot"); } }

The script works I just can't get it to revert back to it's original state. Please help

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by phil_me_up · Mar 02, 2016 at 01:29 PM

You might want to look at using Animation Controllers which exist to help you manage the states of your animation, including how and when you can move from one animation to another.

In this case, you can set triggers / bools in the animation controller to specify if you're aiming and how you can transition into that animation (if you're allowed to - you'll find later on that when yo have more states like 'reloading', using a state machine takes away the effort of having to check if you can move from one state to the other manually).

Normally you'd have one animation for 'idle to aim' and another for 'aim to idle'. However, if you really want to share the same animation clip then you can just set the animation speed to -1 (i.e. reverse). Note I've not actually tried this so I may be wrong.

http://docs.unity3d.com/Manual/class-AnimatorController.html

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
avatar image
0

Answer by mine00123 · Mar 22, 2016 at 02:05 PM

Have you tried using GetButtonDown for "Fire1" and GetButton for "Fire2"? That way, you should be able to click the mouse0 button to shoot, and hold the mouse1 button to aim. So, something like:

 function Update () {
     if (Input.GetButtonDown("Fire1")) {
         GetComponent.<Animation>().Play("aim");
         }
     if (Input.GetButton("Fire2")) {
         if (Input.GetButtonDown("Fire1")) { 
             GetComponent.<Animation>().Play("aimandshoot");
         }
     }
 }


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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Reload animation makes gun too high 0 Answers

Flipping Animation/Jumping animation 0 Answers

Animator Position VS Script Vector 3 0 Answers

Meeting Animation parameters with an AI sprite. 0 Answers

Interchangeable animations in a script? 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