how to make player open door?


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

(I animated the door in unity)

more ▼

asked Apr 08, 2011 at 05:40 PM

avatar image

Michael 20
32 44 33 34

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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 :)

more ▼

answered Apr 08, 2011 at 05:55 PM

avatar image

1k 261 213 225

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

Apr 08, 2011 at 06:42 PM Michael 20

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

Apr 08, 2011 at 06:59 PM OrangeLightning

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:


or try this link for help:


Apr 08, 2011 at 08:33 PM MC HALO
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 08, 2011 at 05:54 PM

avatar image

41 25 18 21

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

Apr 08, 2011 at 05:56 PM MC HALO

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

Apr 08, 2011 at 06:03 PM Paige

No prob glad it was useful :)

Apr 08, 2011 at 06:04 PM MC HALO
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Apr 08, 2011 at 05:40 PM

Seen: 4947 times

Last Updated: Apr 08, 2011 at 05:40 PM