How can I get it? I want to write something like
SortingLayerEnum sortingLayer
So I can pick a sorting layer without using a string.
How can I get it? I want to write something like
SortingLayerEnum sortingLayer
So I can pick a sorting layer without using a string.
Scripting with sorting layers requires strings. You can try to work around it with an enum if you want by creating an enum and having a dictionary or something that you can use the enum as a key to return strings, so you can keep all the strings in one place if you need to change them. You’d have to change your dictionary every time you add or change the name of a sorting layer in unity. But the way Unity is built, you’ll still have to use the strings somewhere, sadly, to reference things like sorting layers and tags in script. There’s no built-in functionality to replace the strings with enum.
Something like this should work:
public class SomeObject : MonoBehaviour
{
public enum ObjectType { Star, Planet, Moon, Asteroid, Comet, Station, Shipyard, JumpGate, Ship };
public ObjectTypes OurObjectType;
}
In the inspector OurObjectType will be a dropdown list of the types defined.