2
\$\begingroup\$

When comparing tags sometimes I can do a typo. For example I might miss type Enmy instead of Enemy and loose some time when trying to find the bug. Is there a way to access all tags before the compiling. So intellisense can auto complete the tag. I am looking for something like this:

 if (ParentObject.tag == "Enemy")
 {
     Debug.Log("String comparison");
 }
 
 if (ParentObject.tag == UnityAllTags.Enemy)
 {
      Debug.Log("Safe comparison");
 }
\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

Ok I found a editor script that creates a new static class with all the tags when project is saved. Here is the link to script: https://gist.github.com/gpelletier0/c6989bf5bf25dfb8b8051204baa65865

Generates a type safe representation of the tags and layers you can set up in the project settings.

How To Install:

Put this file somewhere in an 'Editor' folder.

How To Use:

When you make changes to the tags and layers in the project settings the tool will generate two scripts in the project folder which contain two static classes for Tags and Layers.

You can change the path where the scripts are created in the Preferences window(Edit/Preferences).

private void OnTriggerEnter(Collider other)
    {
        if (other.tag == Statics.Tags.MyCustomTag)
        {
            Debug.Log("awfa");
        }
    }

I want to thank Cristian Geambasu @daemon3000 for creating this script and also Guillaume Pelletier @gpelletier0 for updating it.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .