tag(=scriptname).boolean == true Doesnt work, why not?

Hi all at Unity Answers!
I have been working on a project that contains a lot of scripts.
Most of those script work with the tags of gameobject, but i’ve run into a bump with using the tag as script reference.
The other script I’m trying to acces is called Door1 and the tag of the gameobject it is attached to is also called Door1. Now I want to use a general script that uses the tag of the gameobject to acces this Door1 script.

The script looks like this:

function OnMouseDown(){
      if (Door1.doorOpen == true){
           //do something
     }
}

I want to have it like this:

var myTag;

function Start(){
   myTag = this.gameObject.tag;
} 

function OnMouseDown(){
	if (myTag.doorOpen == true){
		//do something
        }
}

This all looks very solid to me, even print(“myTag”); shows me Door1, but somehow I cant get it to work when using myTag instead of Door1. It does work if I put in Door1 instead of myTag. Can anyone help me with this? I really got no clue why it isn’t working.

Thanks in advance!

Kenneth

myTag doesn’t have the doorOpen variable, because myTag is a string. You need the Door1 script component to gain access to it’s variables, and not the tag. It’s a bit difficult to guess your context, but I believe you want something like:

var door: Door1 = gameObject.GetComponent(myTag);
if(door && door.doorOpen) {
   // do something
}

With this, you are using the tag as the identifier to the script/component you want to get. WIth your example, you trying to perform operations on the tag, which again is just a string, but what you need to do is use the tag to get the component so that you can run your operations on the component.