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 chrishall · Jun 08, 2013 at 10:06 AM · animationtriggerkeyopenpress

How do I play an animation with the 'E' key when I enter a trigger

Hi i'm making a horror game an I download the free Locker asset from the asset store. It comes with an Open and Close animation. I made a box collider trigger so when the player enters the trigger, if the E key is pressed the animation will play. The script I have is not working please help! Iv put the script on the trigger, and added the locker to the GameObject variable, and the open animation to the AnimationClip variable.

 var open: AnimationClip;
 var door: GameObject; 
 
 function OnTriggerEnter (){
 
 if (Input.GetKeyDown("e"))
          {
              animation.Play("open");
          }
 
 
 }
Comment
Add comment · Show 25
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 Scribe · Jun 08, 2013 at 10:08 AM 1
Share

have you tried OnTriggerStay()? I believe OnTriggerEnter() is only called on the frame when the two colliders touch rather than during the time they are touching.

Scribe

avatar image chrishall · Jun 08, 2013 at 10:15 AM 0
Share

hmm okay I think that might work, I tried it but I got this after testing it:

$$anonymous$$issingComponentException: There is no 'Animation' attached to the "LockerTrigger" game object, but a script is trying to access it. You probably need to add a Animation to the game object "LockerTrigger". Or your script needs to check if the component is attached before using it.

avatar image Scribe · Jun 08, 2013 at 10:17 AM 0
Share

Have you selected an animation for your 'open' variable in the hierachy?

avatar image chrishall · Jun 08, 2013 at 10:19 AM 0
Share

yes I dragged the Open animation to the variable

avatar image KiraSensei · Jun 08, 2013 at 10:29 AM 0
Share

The game object containing this script must have an animation called "open". your variables "open" and "door" are useless here.

Show more comments

2 Replies

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

Answer by KiraSensei · Jun 08, 2013 at 12:26 PM

So this game object is useless.

Attach your box collider, your script and the animation to the game object that needs to be animated.

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 Cence99 · Jun 09, 2013 at 03:18 PM

I think the problem is, that the AnimationClip variable is senseless (you're not using it anywhere) and you should simply drag the clip "open" into the Animation component of your Door. Then you should be able to call "animation.Play("open");" or "animation.PlayOneShot("open");"

Also note that one of the GameObjects needs a Rigidbody to make OnTrigger-functions work.

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

17 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

Related Questions

Open door with key 2 Answers

Starting animation with collision 0 Answers

play animation when press key 2 Answers

Trigger enabling keys 1 Answer

Seven key press 3 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