Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Kwayzie · Aug 31, 2013 at 05:55 PM · animationcollidertriggerdoorhorror

play a door animation with collider

so i have to 2 scripts that seem like they should work to me but since i have like no experience with scripting it may be completely wrong. i have a door that i animated to be like a slamming door. attached to that object i have this

 var closeAnimationString : String;
 
 function React()
 {
     animation.Play(closeAnimationString);
 }

now i have a box collider with this this script

 function OnTriggerEnter(hit : Collider)
 {
     if(hit.gameObject.name == "door slam trigger")
     {
         gameObject.Find("girls door").SendMessage("React");
     }
 }

i get no errors but nothing happens when i enter this box. am i doing something way wrong? or is there a simpler way to do this?

Comment
Add comment · Show 3
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 Vonni · Aug 31, 2013 at 06:01 PM 0
Share

Is it a trigger?

avatar image Kwayzie · Aug 31, 2013 at 06:30 PM 0
Share

yes, or thats what i want to make it

avatar image Vonni · Aug 31, 2013 at 06:43 PM 0
Share

You have onTriggerEnter on the object you're moving? Then this wont work. Because onTriggerEnter needs to be on the trigger itself. You could use OnCollisionEnter ins$$anonymous$$d.

1 Reply

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

Answer by aldonaletto · Aug 31, 2013 at 06:40 PM

In the code above, the box collider expects that an object named "door slam trigger" enters it. If the box collider is the "door slam trigger" object, you must instead compare the hit.name to the name of the object that enters it - supposing that the player is the "First Person Controller", do it like this:

 function OnTriggerEnter(hit : Collider)
 {
     if(hit.gameObject.name == "First Person Controller")
     {
        gameObject.Find("girls door").SendMessage("React");
     }
 }
Comment
Add comment · Show 2 · 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 Kwayzie · Aug 31, 2013 at 07:01 PM 0
Share

@ vonni no the OnTriggerEnter is a box collider that i want to be the trigger and is not on the door itself.

and i changed the game object name like u said and it makes more sense now but now when i enter the box i get a nullreferenceexception NullReferenceException UnityEngine.GameObject.Send$$anonymous$$essage (System.String methodName) (at C:/BuildAgent/work/cac08d8a5e25d4cb/Runtime/ExportGenerated/Editor/UnityEngineGameObject.cs:380) switcher.OnTriggerEnter (UnityEngine.Collider hit) (at Assets/Scripts/switcher.js:5) no idea what that means.

avatar image Kwayzie · Sep 01, 2013 at 07:05 PM 0
Share

i ended up fixing the problem. the girls door was suppose to be capitalized because thats how it is in my hierachy. :)

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

Triggering door animation with collider 2 Answers

How do I make the enemy ai animations play after the player exit the on trigger collider on the enemy ai 0 Answers

Trigger to make another trigger to appear? 2 Answers

Trigger door animation with external trigger 1 Answer

Raycasting fail 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