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
1
Question by PongPenguin · Jan 22, 2021 at 03:49 PM · script.animator controllerbool

How to set a Bool value from a C# script into an bool value in a animator?

Pretty much the title, I already have a ground check in my C# script using

 public Transform groundCheck;
 public float groundDistance = 0.4f;
 public LayerMask groundMask; } void Update()
 { isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

So is there anyway to get this same bool balue of isGrounded into the animator? If not maybe set the animator bool = isGrounded. (Sorry about the fomating, new to both coding and asking questions here)

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

3 Replies

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

Answer by PongPenguin · Jan 25, 2021 at 09:53 AM

Figured it out, solution was to set the Grouned variable in animator parameters to the isGrounded from my script. anim.SetBool("Grounded", isGrounded);

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
1

Answer by IBXCODECAT · Jan 22, 2021 at 04:17 PM

Your going to have to give a little bit more of an explanation here on how your animations are set up. However, it sounds like you have multiple animation clips and are wanting to transition through them inside of the animator. You can create a bool value in the animator under parameters, and call it 'ground'.


Then in your code you would need to make sure using the unity animations put this line at the very top of your C# script:

 using UnityEngine.Animations;


After that you need get a reference to the animator from the inspector by using a global serialized variable so you can change the animation parameter at run time:

 [SerializeField] private Animator anim;

this line would go where you are declaring your global variables


After that you can use the function SetBool() to set a Boolean parameter in the animator you have a reference to:

 anim.SetBool("Name of parameter", value);

The "Name of parameter" is what you called your parameter in the animator, and the value would be true or false in this case because it is of type boolean.


Whenever you transition to an animation clip you can add a parameter and require that the parameter is a certain value in order to transition. Use your code to change the parameters.


Here's some more documentation: https://docs.unity3d.com/ScriptReference/Animator.SetBool.html

I hope this helps.

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 PongPenguin · Jan 22, 2021 at 04:57 PM

@IBXCODECAT I have filled in certain parameters already such as Grounded, isMoving and Jump. I already have a groundcheck from a controller made by Brackeys: https://www.youtube.com/watch?v=_QajrabyTJc And what I want is to refer to that groundcheck in my Animator.

In my animator i have a walk animation that goes into a jump animation and I dont want the jumping animation to transition until the Ground Bool is true. I have another grounded bool in the animator which could do this but if it could share the value with the one from the controller it would be nicer is what im thinking. So my question is, how I could do this if even possible. Thanks for you time

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

140 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

Related Questions

How do i use the animator avatar mask to combine two animations ? 0 Answers

Animator override script is not entirely read 0 Answers

Trying to learn Java Script but having some issues...with this code. 0 Answers

Aligning animation with movement. 0 Answers

Simple controller is not so simple,Trying to animate with Bools 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