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 Alienjesus · Apr 01, 2011 at 06:38 PM · animationparentchild

Accessing a child's animation to play or stop it

OK, this is probably a nice simple question for someone out there, but it's causing me some problems. I have a switch on the base of a fan which can be turned on or off. This sends out a message to the fans switchscript, which flips the switch, and SHOULD start or stop the animation of the fan itself, which is a child of the fanbase object.

However, the code I'm using to do so is obviously incorrect (it lets me run the game, but when it should start or stop the animation, it gives the following error: NullReferenceException Fanbaseswitchscript.TurnedOff () (at Assets/Scripts/Fanbaseswitchscript.js:4))

Anyhow, here's my code. If someone could point out the error (I assume with syntax), it'd be much appreciated.

function TurnedOff () { transform.Find("Box002").transform.localPosition.x = -0.09; transform.Find("Fanhead").animation.Stop("Take 001"); }

function TurnedOn () { transform.Find("Box002").transform.localPosition.x = 0.09; transform.Find("Fanhead").animation.Play("Take 001"); }

When the switch is turned, it sends either a 'TurnedOff' or 'TurnedOn' (lol) message to this script. This then moves the box which represents the switch (to show its been switched), and should either play or stop the animation for the fan.

Edit: Here's a screenshot showing the fanhead objects inspector window: http://i112.photobucket.com/albums/n162/alienjesus/screenshot.jpg

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

2 Replies

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

Answer by Alienjesus · Apr 02, 2011 at 05:47 PM

Solved it, it was a really stupid mistake - I had childed Fanhead to fanbase whilst the game was playing, so it hadn't saved. Oops!

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 DaveA · Apr 01, 2011 at 07:05 PM

That's probably this line:

transform.Find("Fanhead").animation.Stop("Take 001");

and that error usually means something before the . is missing. Did you spell Fanhead correclty? FanHead maybe?

Comment
Add comment · Show 4 · 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 Alienjesus · Apr 01, 2011 at 07:08 PM 0
Share

Nope, Fanhead is spelt exactly how it should be.

avatar image DaveA · Apr 01, 2011 at 08:43 PM 0
Share

Then perhaps the object with Fanhead on it does not contain an 'animation' component? Can you post a screenshot of your editor window?

avatar image Alienjesus · Apr 02, 2011 at 04:55 PM 0
Share

Added a screenshot.

avatar image Alienjesus · Apr 02, 2011 at 05:46 PM 0
Share

Solved it, it was a really stupid mistake - I had childed Fanhead to fanbase whilst the game was playing, so it hadn't saved. Oops!

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

No one has followed this question yet.

Related Questions

Make a simple tree 1 Answer

Children won't animate 2 Answers

[Solved] Animation destroying along with the GameObject its a child of 1 Answer

Problem with parent and child animation 1 Answer

Child Parent problem 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