Problem assigning enum value

Hi everyone,

This is probably stupidly easy, but I’m busting my brains with this.

I made this Enum

public enum EyeState{Enabled, disabled, destroyed};

Then created the variable in a monobehaviour

public class EyesDamageReciever : MonoBehaviour {

	  	public EyeState myState;

The idea is, that when the player deals damage to it, instead of simply destroy the object it changes the enum value.

IEnumerator CheckLife()
	{
		rend.material.color = Color.red;
		
		yield return new WaitForSeconds (0.25f);
		
		if (currentHP <= 0) 
		{
			if (myState == EyeState.Enabled)
			{
				myAI.EyeDestroyed(this.name);
				//ChangeMyState(myState);
				myState = EyeState.disabled;
			}
		}
		yield return new WaitForSeconds (0.25f);
		rend.material.color = Color.white;
		
		yield break;
	}

But nothing is happening. I tried debugging it and a warning saying “The requested item has been unloaded” I don’t know if this has something to do with the problem. I googled the warning but every result says they have problem reading the variable. I’m having problems changing it.

Any solutions? Am I making a wrong use of enums?

Sorry for my horrible english…

You say myState does not change. Do you mean this block

if (myState == EyeState.Enabled)
{
    myAI.EyeDestroyed(this.name);
    //ChangeMyState(myState);
    myState = EyeState.disabled;
}

If so you need to verify some things. Try adding some debug statements like so

IEnumerator CheckLife()
{
    rend.material.color = Color.red;

    yield return new WaitForSeconds (0.25f);

    Debug.Log("CheckLife: currentHP = " + currentHP + ", myState = " + myState.ToString());
    if (currentHP <= 0) 
    {
        Debug.Log("currentHP is <= 0");
        if (myState == EyeState.Enabled)
        {
            // if you see this debug statement then you need to place some debug statements inside myAI.EyeDestroyed() - follow the trail till you find the culprit
            Debug.Log("myState == EyeState.Enabled, calling myAI.EyeDestroyed(" + this.name + ")");
            myAI.EyeDestroyed(this.name);
            //ChangeMyState(myState);
            myState = EyeState.disabled;
        }
    }
    yield return new WaitForSeconds (0.25f);
    rend.material.color = Color.white;

    yield break;
}