using UnityEditor;
using UnityEngine ;
public class addTag:MonoBehaviour
{
public GameObject o;
void Start(){
AddTag("MXLWD",o);
}
void AddTag(string tag,GameObject obj)
{
if(!isHasTag(tag))
{
SerializedObject tagManager = new SerializedObject(obj);
SerializedProperty it = tagManager.GetIterator();
while (it.NextVisible(true))
{
if(it.name == "m_TagString")
{
Debug .Log (it.stringValue );
it.stringValue =tag;
tagManager.ApplyModifiedProperties();
}
}
}
}
bool isHasTag(string tag)
{
for (int i = 0; i < UnityEditorInternal.InternalEditorUtility.tags.Length; i++) {
if (UnityEditorInternal.InternalEditorUtility.tags[i].Equals(tag))
return true;
}
return false;
}
}