• 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
Question by Michael 20 · Apr 08, 2011 at 05:40 PM · playerdooropenanimatecollide

how to make player open door?

Hi

How can I make a script that can make a door open when the character collides with it?

(I animated the door in unity)

Comment
MC HALO

People who like this

1 Show 0
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

  • Sort: 
avatar image

Answer by MC HALO · Apr 08, 2011 at 05:55 PM

Ok this is what you need to do :


function OnControllerColliderHit(hit: ControllerCollider) {

if(hit.gameObject.tag == "Door"){ hit.animation.Play(" Put you Unity Animation name in here" );

} }

this will open the door if the player collides with it but in order for it t o work you need the door object to have the following tar attached to it "Door" then wait and see.


Example 2:


function OnCollisionEnter (hit: Collision){

if(hit.transform.tag == "Door"){

 animation.Play("Put your Unity door animation name here ");

} }


Dont forget to tag the door object in unity if you dont know how to make tages do the following:

Click on the door gameObject and in the Inspector Mode look for "Tag"

if you find Tag click on it and a drop down menu will drop down from there select "Add tag"

and from there create a new tag called "Door"

then click on the door game object again and then click on tag and then add the tag that you created to the door

hope this helps :)

Comment
Paige

People who like this

1 Show 3 · 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 Michael 20 · Apr 08, 2011 at 06:42 PM 0
Share

when I add "door" to tag it is appearing in the (Layer) list and not in the (Tag)

avatar image FLASHDENMARK · Apr 08, 2011 at 06:59 PM 0
Share

@Michael There is a little triangle next to the "tags" pop that open and add your tags there.

avatar image MC HALO · Apr 08, 2011 at 08:33 PM 0
Share

Yep OrangeLightning is right. click on the player on the Inspector mode click where it says tag and then select new tag. once you have done that you will see list of layers. On top of that you will see something called tags and next to that you will have a little triangle click on that and then a list of tags will fall down from there add your tag. here is a link:

http://unity3d.com/support/documentation/Components/class-TagManager.html

or try this link for help:

http://unity3d.com/support/documentation/Components/Tags.html

avatar image

Answer by Paige · Apr 08, 2011 at 05:54 PM

I haven't tried out animations yet, but if I were to guess from my knowledge so far, I would say just have on the character controller an on collider enter function with the animation starting when the player hits the door.

Comment

People who like this

0 Show 3 · 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 MC HALO · Apr 08, 2011 at 05:56 PM 0
Share

its easy :) have a look at the example below :)

avatar image Paige · Apr 08, 2011 at 06:03 PM 0
Share

yup, figured it was something easy like that, I just didn't know the animation code yet to help him out. nice one

avatar image MC HALO · Apr 08, 2011 at 06:04 PM 0
Share

No prob glad it was useful :)

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Opening, Closing, Keeping door open at proximity 1 Answer

open and close a door with a keypress 6 Answers

Open & Close a simple door animation with sound and door states 1 Answer

Shooting target to trigger a door to open 1 Answer

Score Question Java Script, 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