Need help with an editor script if possible,
Does anyone know if there is a way to create a new custom Tag in the Unity editor? C#
Thanks in advance,
Need help with an editor script if possible,
Does anyone know if there is a way to create a new custom Tag in the Unity editor? C#
Thanks in advance,
Select the object, click tag, at the bottom Add Tag, open the tag section, fill in an empty slot, press enter.
Your new tag shows at the bottom of the list.
EDIT:
In case of misunderstanding, you cannot assign a tag in the editor without first declaring it in the tag list as mentioned above. If you try to create a tag in the script, it returns an error.
What you can do though is swap existing tags at runtime.
function Start(){
gameObject.tag="Friend";
}
function Update(){
if(pissedOff)gameObject.tag="Enemy";
}
That will modify the tag of the object and for instance, if you could not kill a friend you could now kill an enemy.
I get the feeling you want to create a Tag for further use using C#, as opposed to making it using the preferences and then assigning it later.
If you want to make a Tag using C#
I don’t actually know of any way to do this, but you might consider that if you’re dynamically creating Tags to assign to objects, you may not be using Tags in the most efficient way. If you’re looking for individual identifiers, then you can do that on a name basis while having an archetypal tag, which is how I handle procedurally generating and identifying obstacles (asteroids, detritus, etc…).
If you want to make a Tag in general
You probably don’t need to be told this, but the question was just vague enough for me to think I should put this up anyways.
Go to the menu and select “Edit” => “Project Settings” => “Tags” and the inspector will display Tags and Layers. You’ll likely want to expand Tags (as it isn’t expanded by default, and you don’t want to confuse Tags with Layers), then add your own in the appropriate Element field.