I am not familiar with script.
In my scene there are two building, and both have a its own door. Then I followed a vedio tutorial and copy Javascript into my project. Below is the script named playercollisions I have modified.
var doorOpened : boolean = false;
var timer : float = 0.0;
function OnControllerColliderHit(hit:ControllerColliderHit){
if((hit.gameObject.tag == "house1door") && (doorOpened == false)){
openDoor();
}
}
function Update(){
if(doorOpened){
timer += Time.deltaTime;
}
if(timer >= 3){
shutDoor();
}
}
function shutDoor(){
var theHouse = gameObject.FindWithTag("house1");
theHouse.animation.Play("doorshuts");
doorOpened = false;
timer = 0;
}
function openDoor(){
doorOpened = true;
var theHouse = gameObject.FindWithTag("house1");
theHouse.animation.Play("dooropen");
}
Then I added the script to First Person Controller(Its tag is "Player").And added "house1" tag to the two buildings in the scene, and added "house1door" tag to the two doors of each building. I renamed the same name with the animations of the two models. Opening animation of the two buildings has the same name "dooropen", and shutting animation name is "doorshuts". But when I run the game, player can open doorA and can't open the other doorB. Then I quit Unity and restart, run the game and I found I could open doorB and couldn't open doorA. What can I do to solve the problem? Thanks a lot!