dublicated door & animation problem

Hey, I know this is asked like thousand times, but can’t figure it out… :(.

there is my script which is on my door objects sensor, and it plays parent objects animation(door hinge) door works great, but when I dublicated door it plays only 1 door animations even if you’re on another door’s sensor.

So, how can I get this script working on multiple doors?

var guiEnable = false;

private var doorOpen = false;

function OnGUI()
{
	if (guiEnable)
	{
		GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30),"Press F to open the door");
	}
}

function OnTriggerStay(other : Collider){
if (other.gameObject.tag == "Player") {

door=GameObject.Find("sisäovi");
   
	if (Input.GetButtonDown("F"))
	{
				if (doorOpen ==false)
				{
				yield WaitForSeconds (0.5);

					  door.transform.animation.Play("door2 open");
					doorOpen = true;
				}
			
				else if (doorOpen ==true)
				{
				yield WaitForSeconds (1);
					   door.transform.animation.Play("door2 closen");
					doorOpen = false;
				}
	}
		guiEnable = true;
	}
}

function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") 
	{
		guiEnable = false;
	}
}

I did solved this myself.

I replaced this one

door.transform.animation.Play("door2 open");

with this

transform.parent.animation.Play("door2 open");

That’s because your script is looking for a gameobject named “door” which means anything named “door” will be referenced.

Rename your duplicate door and that should fix the problem.

Also for performance reasons, you should do referencing in at least the start() function. You can do that like this for example(C# sorry)

public GameObject doorRef;

void start ()
{
 doorRef = GameObject.Find("door"); 
}