Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Dyljt · Mar 03, 2021 at 07:15 AM · boolean

anim.SetBool not working?,Anim.setbool not working?

This is my first time making a game using unity or C# so it could be an easy fix but, as said in the title i cannot figure out how to set the animation bool to true. Here is my code public void hit()

 {
 if (Input.GetKeyDown(KeyCode.RightControl))
 {
         anim.SetBool("chop", 1);
 }
 else
 {
         anim.SetBool("chop", 0);
 }
 }

This code is meant to trigger the attack animation for my character but the bool remains false.,This is my first time making a game using unity or C# so it could be an easy fix but, as said in the title i cannot figure out how to set the animation bool to true. Here is my code public void hit()

 {
 if (Input.GetKeyDown(KeyCode.RightControl))
 {
         anim.SetFloat("chop", 1);
 }
 else
 {
         anim.SetFloat("chop", 0);
 }
 }

This code is meant to trigger the attack animation for my character but the bool remains 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

· Add your reply
  • Sort: 
avatar image
0

Answer by DevManuel · Mar 03, 2021 at 08:29 AM

First of all I would recommend to check if the if-statement is working.

 if (Input.GetKeyDown(KeyCode.RightControl))
      {
              Debug.Log("key clicked -- chop = true");
              anim.SetBool("chop", 1);
      }



Then the value is a boolean. So to just be sure please replace the number 1 and 0 with true and false.


Next question: Does you have set the reference object of 'aim' in the inspector or by script? I think you know it, but for safety: 1. You can set the animator public:

 public Animator anim;

  1. you can set the reference by script:

     private Animator anim;
                         
         void Start(){
            anim = gameObject.GetComponent<Animator>();
            Debug.Log(anim);
         }
    
    

I hope some of my advices helped. Happy coding ;-)

Comment
Add comment · Show 1 · 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 ariankeshvari · Feb 14 at 06:12 PM 0
Share

I've got the same problem and it doesn't work for weird reasons. I just assigned 1 to the "temp" parameter and when I print it in the next line it still says 0. It's super simple code! just three lines! I can't even find out what's the problem

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

116 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

Related Questions

Access a variable from another script in update function 1 Answer

Door Script 1 Answer

How do I check if all booleans in an array are true? 2 Answers

Trigger won't read my Bool change 1 Answer

Trying to create a function that returns a bool 2 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