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 /
This question was closed May 29, 2016 at 12:54 AM by Paul2357 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Paul2357 · May 27, 2016 at 11:32 PM · c#animationunity 5animatormecanim

Issue with mecanim playing an animation using setbool

I'm having issues telling the model to use the attack animation. The animation plays, but I am getting a problem where it just plays the animation regardless of the button press and then just stays there. I've tried a few different variations to try to get it to work, but I'm new to animations and I'm lost right now. I've looked at the api for the setbool and I believe I am using it correctly. Any help would be appreciated. I can include a picture of my mecanim animator if need be.

   //Handles attacking
         if (Input.GetKeyDown(KeyCode.Space))
         {
 
                 //Start animation
                 attack = true;
                 anim.SetBool("attack", attack);
             
 
             // ADD IF STATEMENT HERE TO CHECK MAGIC USES....ENCAPSULATE THE SWITCH WITH 
             // THIS STATEMENT THAT WAY IT IS ONLY CHECKING ONCE THE ACTION IS BEING DONE
             // AKA IF SPACE IS PRESSED -> IF MAGIC USES != 0 -> DO ACTION
             if (MagicUses > 0)
             {
                 
 
                 //Handle Switching Projectiles/Attacks
                 switch (attackNumber)
                 {
                     case 1:
                         Rigidbody shot = Instantiate(fireProjectile, transform.position + (transform.forward * 0.5f), transform.rotation) as Rigidbody;
                         shot.velocity = transform.forward * bulletSpeed * Time.deltaTime;
                         //SoundManager.instance.PlaySingle(fireballSound);
                         MagicUses--;
                         break;
 
                     case 2:
                         playerMove.JumpForce = 400;
                         MagicUses--;
                         break;
                 }
             }
             
             //Stop Animation
             attack = false;
             anim.SetBool("attack", attack);
 
         }

Edit: Link to image below

http://tinypic.com/r/15yezhk/9

Comment
Add comment · Show 3
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 Alec-Slayden · May 28, 2016 at 04:57 AM 0
Share

Do you have a transition out of the animation when attack is set to false?

avatar image Paul2357 · May 28, 2016 at 12:53 PM 0
Share

@alec slayden

Yeah there is a transition. I can add the screen caps once I get back home from work around noon EST

avatar image Paul2357 Paul2357 · May 28, 2016 at 05:03 PM 0
Share

@alec slayden

I uploaded a pic to tinypic and put the link in the updated question

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Paul2357 · May 29, 2016 at 12:53 AM

Well I figured it out. The code was attached to another gameObject (intentional) and was trying to access the animator of that object. Once I declared a game object that was holding the player and an animator that called the get component of the player, it worked fine!

 // Variables
 Public GameObject player;
 Animator otherAnim;
 
 void Awake()
 {
      otherAnim = player.GetComponent<Animator>();
 }
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

Follow this Question

Answers Answers and Comments

187 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

Related Questions

Hello! I have some issues with animations. 1 Answer

How to use mecanim to play specific animation clips when public static int condition is reached? 2 Answers

How to get back to the first position animatedly in unity? 1 Answer

Mecanim: get animation duration from Animator state name 0 Answers

Unity 5 - Starting Mecanim Animation At Specific Time 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