• 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 eirikamb · Jun 24, 2016 at 10:38 PM · c#animatorbooleannot working

Cant change bool parameter in animator in a script

My bool wont change, I want to have an attacking animation, tha attacking animation will start by my bool Angrep gets true, but nothing happens when I press Mouse0.. Here is the script and a picture of my animator... using UnityEngine; using System.Collections;

public class PlayerAttack : MonoBehaviour { // PlayerMovement plMovement; PlayerInput plInput; Animator anim;

 public float comboRate = 0.5f;

 WaitForSeconds comboR;
 public GameObject damageCollider;
 // Use this for initialization
 void Start () {
     plInput = GetComponent<PlayerInput>();
     anim = GetComponent<Animator>();

     comboR = new WaitForSeconds(comboRate);

     damageCollider.SetActive(false);
 }
 
 // Update is called once per frame
 void FixedUpdate () {
     if(plInput.fire1)
     {
         anim.SetBool("isAttacking", true);
    //     plMovement.canMove = false;
         StartCoroutine("CloseAttack");
     }
 
 }
 IEnumerator CloseAttack()
 {
     yield return comboR;
     anim.SetBool("isAttacking", false);
 }
 public void OpenDamageCollider()
 {
     damageCollider.SetActive(true);
 }
 public void CloseDamageCollider()
 {
     damageCollider.SetActive(false);
 }

} alt text

boolanimatorerror.jpg (349.6 kB)
Comment
Add comment · Show 2
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 Habitablaba · Jun 24, 2016 at 10:43 PM 0
Share

I'm pretty sure

 yeild return comboR

is not doing what you expect it to be doing.
Do you mean

 yield WaitForSeconds(comboR);

avatar image eirikamb Habitablaba · Jun 24, 2016 at 11:04 PM 0
Share

It is unfinished... I had this from a tutorial and now I see I only took out half of that unneccesary part

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Invertex · Jun 24, 2016 at 10:39 PM

You're setting the bool "isAttacking", which doesn't appear to exist on the Animator. It should be: anim.SetBool("Angrep", true);

Comment
Add comment · Show 6 · 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 eirikamb · Jun 24, 2016 at 11:08 PM 0
Share

I tried but it didint work so I took out the Enumorator and changed the $$anonymous$$eyCode and now It works except it dont set the boolean false again... I will test out more... Thank you very much, it helped me indirectly

avatar image eirikamb · Jun 24, 2016 at 11:13 PM 0
Share

I took in the Enumerator and now it dont work, do you see the error in that?

avatar image Invertex · Jun 25, 2016 at 12:01 AM 0
Share

In CloseAttack() you should use WaitForSeconds(comboRate);.

Also, you need some conditionals in there to prevent the coroutine from being executed again while it's already running. I would suggest also doing your Play attack, Wait For Seconds, Stop Attack within that coroutine. Have it start the attack, then it waits for the duration in your float variable, and then stops the animation.

avatar image eirikamb Invertex · Jun 25, 2016 at 12:45 AM 0
Share

Thank you very much, you saved my day

avatar image Invertex eirikamb · Jun 25, 2016 at 12:58 AM 0
Share

Good to hear. Don't forget to mark this as answered btw!

Show more comments
avatar image
0

Answer by cstlmode · Jun 25, 2016 at 06:00 AM

try this var Attack : boolean =false; fonction update (){

if(!attack){ Attack =true; anim.SetBool("isAttacking", true); }

}

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation doesn't play 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Set boolean to false when animation changes? 1 Answer

Can't Set Animator Boolean Parameter C# 1 Answer


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