Tag an gameobject at runtime after a condition completed
Hi, I want to change tag of an gameobject at runtime after a condition completed. I use: gameObject.tag = "Myothertag"; but it doesnt work How I can do fix it? Thanks,
In this example, my condition works but the tag does not change.
void Update () {
if (distance < 10 && distance > 0 && gameObject.tag == "Player" )
{
GetComponent<RawImage> ().texture = Disparition as MovieTexture;
audio = GetComponent <AudioSource> ();
audio.clip = Disparition.audioClip;
Disparition.Play ();
Avertissement.Stop ();
Pose.Stop ();
gameObject.tag = "Quit";
}
Answer by saud_ahmed020 · Jan 12, 2017 at 07:45 AM
@vauthier For changing the tag at run time you must add tag "Quit" in Tags list. First set tag "Untagged" and after condition completed gameObject.tag = "Quit" will work. Thanks
Thanks saud_ahmed020
I did it before but it didnt work. I solved the problem by put the line code at the beginning. :/ sometimes I don't understand programmation. If someone understand, that can be good to know. Thanks community,
THIS DOESNT WOR$$anonymous$$ if (distance < 10 && distance > 0 && gameObject.tag == "Player" ) { GetComponent ().texture = Disparition as $$anonymous$$ovieTexture; audio = GetComponent (); audio.clip = Disparition.audioClip; Disparition.Play (); Avertissement.Stop (); Pose.Stop (); gameObject.tag = "Quit"; }
THIS WOR$$anonymous$$S if (distance < 10 && distance > 0 && gameObject.tag == "Player" ) { gameObject.tag = "Quit"; GetComponent ().texture = Disparition as $$anonymous$$ovieTexture; audio = GetComponent (); audio.clip = Disparition.audioClip; Disparition.Play (); Avertissement.Stop (); Pose.Stop (); }
@vauthier I think you did not understand what I said. Go to inspector and define Tag in Tag list. It means if you have tag in tag list then gameobject.tag = "your defined tag" will work at runtime. But if you have not defined tag already then this statement will not work. I hope you will got my point. Thanks