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