Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Mikenekro · May 12, 2014 at 10:04 PM · enemybooleanboolparameters

C# Parameter questions 2D game

Hi I am pretty new to Unity and I need some help with parameters. I know that you can use bool parameters to transition from Any State to another animation.

I have my animation set up and have my Any State transitioning to my Death animation. I have a Dead bool parameter and have the transition set to when Dead = true.

Then in my code I have this in void Update().

 if (animator) {
                         //get the current state
                         AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo (0);
 
                         if (stateInfo.nameHash == Animator.StringToHash ("Base Layer.Any State")) {
                                 if (health <= 0) 
                                         animator.SetBool ("Dead", true);
                         } else if (health > 0) {
                                 animator.SetBool ("Dead", false);                
                         }
 
                 }


For some reason it doesn't work. I have tried everything from just using if(health <=0) animation.SetBool ("Dead", true); vise versa, to a more complicated approach.

For some reason it never recognizes that Dead = true when health = 0. The box won't check during the game for Parameter Dead.

I got it to work for my Ground Bool Parameter to check if you are on the ground.

Not sure if it is because it is in the "health" script and not the controller script. I'm still learning.

The health bar goes down when I come in contact with an enemy, health goes up when I get a health coin. This is the most trouble I have had getting something to work so far.

Comment
Add comment · Show 1
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 Mikenekro · May 12, 2014 at 10:05 PM 0
Share

Forgot to mention. I have animator = GetComponent(); in void Start()

and

 protected Animator animator;

at the top

1 Reply

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

Answer by Mikenekro · May 12, 2014 at 10:31 PM

Ok so I got it to check the "Dead" parameter by taking all of that out and just using this.

 if (health == minHealth)
                         animator.SetBool ("Dead", true);

lol So simple too.

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

20 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

Related Questions

Boolean and input relation 0 Answers

(C#) My enemy dosent take damage ScriptFix 1 Answer

How can I use 1 key instead of two for toggling animation ? 2 Answers

I'm having trouble setting a bool. 2 Answers

How do I check a variable of an instantiated object from another instantiated object? 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