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 JoshC · Dec 06, 2013 at 06:52 PM · animationcollisiongameobject

Animation not playing via collider and script (game just chugs instead)

Hello.

In an FPS game, I am trying to get a box to play an open animation whenever the player collides with it.

The box has ana animation that opens its lid (the lid is a child of the box). Whenever a copy of the asset is created, its animation will play automatically whenever the game loads, as expected.

I have the following script attached to the First Person controller:

 function OnControllerColliderHit(hit : ControllerColliderHit)
 {
     if(hit.gameObject.tag == "chest")
     {
         hit.GameObject.animation.Play("box_open");
     }
 }

Next, I add a Box Collider to the box object (parent, not the lid) and disable "Play Automatically" in its Animation component. I then add a "chest" tag to it for the script.

When the player walks into the object, no animation is played and the game actually chugs while the player is in contact with the box.

I am definitely missing something here, just not quite sure what it is. Any assistance would be greatly appreciated.

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

Answer by meat5000 · Dec 06, 2013 at 07:02 PM

hit.GameObject.animation.Play("box_open");

GameObject typo

GameObject is a Type gameObject is an object

Does the box have a rigidbody?

Comment
Add comment · Show 1 · 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 JoshC · Dec 06, 2013 at 07:14 PM 0
Share

Gah! That was totally it! I didn't notice that typo.

Thank you much for your help. :)

avatar image
0

Answer by Rams · Dec 06, 2013 at 08:02 PM

You have to probably use animation events. Do as below process... 1)open animation editor(box_open) and select an animation event at starting and attach it to the method.code will be...->

take another var(for ex: hit1) of type ControllerColliderHit in the starting, assign hit to hit1(making reference). if(hit.gameObject.tag == "chest") call that method.

in the method definition hit1.gameObject.animation.play("box_open").

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

18 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

Related Questions

How could it be done "Cooldown" for a shield ? 2 Answers

Animation Question with PlayMode 1 Answer

How do I make objects disappear as they are touched? 1 Answer

How to destroy a gameobject on collision 2 Answers

How to destroy a specific gameobject on collision. 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