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)

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.

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