How to use one script for two objects? [Door opening]

I have 2 door on my scene and I open/close it using animation. I use the same script for each door (each door object have it’s own script component) and when I open one door, the other are opens too. How can I detect, which door should I open?

For both doors I use the same animation

public Animation doorAnimation;

private bool isDoorClosed;
private bool isAimationReadyToPlay = true;

void Update ()
{
    if (DoPlayerLookAtButton() && Input.GetButton("Fire1") && isAimationReadyToPlay)
        OpenCloseDoor();
}

bool DoPlayerLookAtButton()
{
    RaycastHit _hit;
    Ray _ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
    bool isHit = Physics.Raycast(_ray, out _hit, 1.5f);

    if (isHit) return true;
    else       return false;
}

void OpenCloseDoor()
{
    StartCoroutine("DelayBetweenAnimations");

    if(!isDoorClosed) // Open door
    {
        doorAnimation["openDoor"].speed = 1.0f;
        doorAnimation.Play();
    }
    else // Close door
    {
        doorAnimation["openDoor"].speed = -1.0f;
        doorAnimation["openDoor"].time = doorAnimation["openDoor"].length;
        doorAnimation.Play();
    }

    isDoorClosed = !isDoorClosed;
}

IEnumerator DelayBetweenAnimations()
{
    isAimationReadyToPlay = false;
    yield return new WaitForSeconds(0.5f);
    isAimationReadyToPlay = true;
}

Physics.Raycast() returns true if it hit anything, so your doors should also open when you click on a wall.
So the thing you should check is if it did hit this door, and you can find this in the hit variable you just declared :

//add at the start : 

Collider thisCollider;

public void Start(){
   thisCollider = GetComponent<Collider>();
}

//in DoPlayerLookAtButton : 

bool DoPlayerLookAtButton()
 {
     RaycastHit _hit;
     Ray _ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
     bool isHit = Physics.Raycast(_ray, out _hit, 1.5f);
     if (isHit && _hit.collider == thisCollider) return true;
     else       return false;
 }

That should do the trick, but if not comeback and we will fix it.

Hope it helps you.

this is your error
bool isHit = Physics.Raycast(_ray, out _hit, 1.5f);
no matter what it hit, it will return true.

use if(hit.collider.name == this.name)
and make sure each door have a different name

also, just by doing

if (Input.GetButton("Fire1") )
        if(DoPlayerLookAtButton() && isAimationReadyToPlay)
             OpenCloseDoor();

You would get a lot of performance since you raycast only when the button is pressed,

Technically, this is not an answern but i didnt want it to get lost in the comments. Please do not flame me.

I place boxes with trigger colliders but no meshes rendered as part of my door prefab. Standing where you can open a door puts you in the box so the box trigger lets me know someone is in front of the door trying to open it. You can use code so they have to press a button to open it, or just open it if something enters the box, like electronic eye at the supermarket, or pressure pads.

Not 100% sure, but i believe thats less costly than a raycast.