Im trying to get the type of enum so when i click depending on the type i want it to do something...


public enum ItemType
{
    Food,
    Potion,
    Weapon,
    Shield,
    Default
}
public enum Attributes
{
    Strength,
    Stamina,
    Health

And then here when i click i would like the click to do diff things depending on the type of item. Im very new at coding so any help would be much appreciated


public void OnClick(PointerEventData pointerEventData)
    {
        for (int i = 0; i < equipment.GetSlots.Length; i++)
        {
            if (ItemType == potion)
            {
            }
        }
    }

Ive probably done this wrong lol this is why i need helP!!

The enum is just a type that you need to create an instance of. If you would for instance want an enum describing what item is equipped you would first create an enum (as you already did) and then create the variable like this:

private ItemType equippedItem = ItemType.Food;

Note how you always need to write out the name of the enum before assigning or comparing values. Let’s say you later wanted to check if the equipped item is a potion you could do it like this:

if (equippedItem == ItemType.Potion):
    // The item was a potion

In your line your line

if (ItemType == potion)

you are checking if the enum itself (which is not a variable) is equal to potion which is a variable you haven’t defined (at least in the code you shared) If you created a variable for the item you could compare it to potion like I showed earlier.

Hope this helps.

im using scriptable object and in the object it defines its type… so then would i just type the middle line you mentioned?