using this.tag as a variable

I’m trying to use this.Tag as a variable and I can’t seem to get it working.

Here is a sample of my code.

function Update(){

var myTag : GameObject;
myTag = this.Tag;

    print("My tag is" +myTag);
}

I would expect that it would create a variable called “myTag” and then it would assign what ever the objects current tag is to “myTag” and would then print out on the console, "My tag is ‘the objects own tag’ ". If I can print it, I can then use the variable elsewhere and in other ways, correct?

When I run the script, the console spits out:

“”“”“”“”“”“”“”“”“”“”

My tag is

UnityEngine.MonoBehaviour:print(Object)

OnTriggerVersionTwo:Update() (at Assets/Standard Assets/Scripts/General Scripts/OnTriggerVersionTwo.js:7)

“”“”“”“”“”“”“”“”“”“”"

I’m a novice so I might be doing something extremely obvious. Any help would be greatly appreciated.

That is a bit weird, why dou you need to use a variable that holds a tag?
Try this: (This prints your Object)

var objectTag: GameObject;

function Update(){

print (“My tag is” + objectTag );

}

this.Tag will return a string, not a GameObject. Try marking your var as a string and try it again. I think that javascript is making it undefined.

function Update()
{
    var myTag : string;
    myTag = this.gameObject.tag; // with a small 't' as well?
    print("my tag is " + myTag);
}