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
4
Question by SebastianRSP · Mar 17, 2014 at 11:00 AM · c#2danimatorbool

C# Acessing animator on another Object

Hey there, I am currently trying to trigger an animator bool with the new 2D Animator tool, what I need to do is this:

 animator.SetBool("Level2", false );

But from another script on another object, and so far it does not work the usual way, by doing:

 public GameObject myObject;
     
     myObject.animator.SetBool("Level2", false );

Any help is appreciated! :D

Comment
Add comment · Show 5
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 frarees · Mar 17, 2014 at 11:10 AM 1
Share

$$anonymous$$ake sure your myObject is holding a valid reference. Access its Animator via GetComponent. $$anonymous$$ake also sure that the animator controller referenced there has the Level2 parameter defined (and that it's a bool!).

avatar image SebastianRSP · Mar 17, 2014 at 02:51 PM 0
Share

@frarees I don't seem to be able to use "GetComponent" can it be that animator is private so that it is not accesible? :)

avatar image frarees · Mar 17, 2014 at 03:04 PM 1
Share

Don't understand what you mean by private animator.

 public GameObject otherObject;
 Animator otherAnimator;

 void Awake () {
     otherAnimator = otherObject.GetComponent<Animator> ();
 }

Does this work for you? What errors/exceptions is Unity throwing?

avatar image SebastianRSP · Mar 17, 2014 at 03:22 PM 0
Share

@frarees Sorry about the private animator thing, my fault. And yes it works like a charm now! Thank you so much for taking your time out to help me :D

avatar image frarees · Mar 17, 2014 at 03:46 PM 0
Share

Glad it worked. You're welcome :)

1 Reply

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

Answer by frarees · Mar 17, 2014 at 03:47 PM

 public GameObject otherObject;
 Animator otherAnimator;

 void Awake () {
     otherAnimator = otherObject.GetComponent<Animator> ();
 }

If otherObject references to a GameObject that has an Animator component on it, otherAnimator will contain a valid reference.

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

22 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

Related Questions

2D Animation does not start 1 Answer

Having multiple 2D Characters 1 Answer

Start sprite animation at the same index that the previous animation stopped 2 Answers

Multiple Cars not working 1 Answer

Having some issues with my Animator Controller. 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