OgiJr
1
Please I am desperate, how do I change a tag during runtime:
I tried what I knew from Unity 4-
I have a tagged Object “Tag1” and have a second tag “Tag2”;
Then I use this:
void Update()
{
gameObject.tag = “Tag2”;
}
and during runtime it switches between “Tag1” and “Tag2”- but its not possible now:( , help me,please.
If you declare the tag in the tag manager, then
gameObject.tag = “DeclaredTag”;
should work fine.
OgiJr
2
The script-
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
void OnMouseClick()
{
gameObject.tag = "UnitSelected";
}
void Update()
{
if (gameObject.tag == "UnitSelected")
{
transform.position = new Vector3 (20,5,0);
}
}
}
I want whenever I click on the object - it will change the tag, but however it is not working it stays tag1 and I am not sure what does defined a tag mean- I mean is it to create a tag?
Deadcow
3
private void Start()
{
tag = “Tag2”;
if (CompareTag(“Tag2”)) Debug.Log(name + " tag is now Tag2");
}
Cartainly works, if you declared “Tag2” in the TagManager.
What specifically do you mean by “not possible now”? What error do you have?
You have a typo on line 8. You’re assigning the tag “UnitSelected”, but testing the tag “UnitSected”.