- Home /
How can i use a tag in my script?
Alright i tried Asking this question but
http://answers.unity3d.com/questions/659831/how-to-make-your-variable-a-scenes-gameobject-by-t.html
I guess Unity3d doesn't have that option available.
So now i tried looking up on how to usea tag in the way i want to use it. But... Can't find anything.
So i just decided to ask a simple question.
There are lots of ways of using tags as indicated by 'haim96'. Your earlier question did not get answered because it was difficult to understand what you were asking.
Answer by haim96 · Mar 12, 2014 at 05:01 PM
you can use:
if(gamesobject.tag=="some tag")
{
do something
}
or use GameObject.CompareTag:
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.CompareTag.html
you can also find object in scene with GameObject.FindGameObjectsWithTag https://docs.unity3d.com/Documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html
Alright cool thanks for replying but.
function Update(){
if ($$anonymous$$athf.Approximately(gameobject.tag == "Card".transform.position.x, Zone1 ))
{print("Thi is working.");}
}
How would I use it like this?
Like how can it find the tag of all Objects with the Tag named "Card" in them?
Like if a GameObject named Card as it's Tag, is approximately To some number then Something magical happens.
var thecard: GameObject;
thecard = GameObject.FindWithTag ("card");
if ($$anonymous$$athf.Approximately(thecard.transform.position.x, Zone1 ))
{print("Thi is working.");}
Thanks for replying quick and accurate.
Answer has been submitted. Thumbs Ups