Enums not working (I think)

Hey guys, not sure why this isn’t working. I followed everything I read but the color isn’t changing. I’m new to enums. What I’m hoping to do, is to have lets say a potions, with different colors. So like a potion prefab with the option to change it’s color. instead of having to have many different potions. Of course I would later want to add different stats (empty/full) Different Sizes etc. Are Enums the way to go? I went with enums because I want to be able to have the drop down menu in inspector :slight_smile:

Thanks a bunch

Here’s a script:

public class MyEnums : MonoBehaviour {

public enum ColorState 
{

Mana,
Health,
Energy,
Spell

}

public ColorState colorState;

public void update()
{
	if (colorState == ColorState.Mana)
	
	renderer.material.color = Color.yellow;
	Debug.Log("this happened");

}

}

Your method should be called Update not update

Also use

if (colorState == ColorState.Mana) {
     renderer.material.color = Color.yellow;
     Debug.Log("this happened");
}

Hi Hathakas. There’s a few things to note with this piece of code. Can I suggest that the following might actually be more what you’re looking for:

using UnityEngine;
using System.Collections;

public enum ColorStates
{
    None,
    Mana,
    Health,
    Energy,
    Spell
}

public class MyEnums : MonoBehaviour
{
    public ColorStates ColorState;
    void Update ( )
    {
        switch ( ColorState )
        {
            case ColorStates.Mana:
            renderer.material.color = Color.yellow;
            break;

            case ColorStates.Health:
            renderer.material.color = Color.red;
            break;

            case ColorStates.Energy:
            renderer.material.color = Color.blue;
            break;

            case ColorStates.Spell:
            renderer.material.color = Color.green;
            break;

        }
    }
}

You may want to check out the videos on delegates and events as well. Every time you change your color state would be the best time for a material color change.