How to make player open two or more different doors?

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!

GameObject.FindWithTag only finds the first object with that tag.

You need to pass the object you hit as an argument. There's little reason to use any Find function outside of a Start or Awake script if it can be helped.

if((hit.gameObject.tag == "house1door") && (doorOpened == false)){
        OpenDoor( hit.gameObject );
    }   

function OpenDoor( go : GameObject ) {
  go.animation.Play(whatever);
}

Also, keeping functions named in CamelCase will help with code readability in the long run. :)

I found similar scripting in Unity Game Development essentials book, where you must collect 4 batteries in order to open the door. The script works fine when you duplicate the building and have collected the 4 batteries once.

Could you point out which video tutorial were you following. and try duplicating the working building, if that doesn't work make sure you have requirements to open the door. I believe you have that script attached to player and you only have a tag on the door, just like in the tutorial i followed, in that sense it should work.

In general i recommend for doors that you use a raycast and not a box collider. With raycast the player must look at the door in order to open it. And cant reverse to the building.

If the tutorial comes with link to a complete project, check that you have everything the same, and ask the maker of tutorial can you use this script for multiple buildings, or post a link to the video and i'll have a look.