Enum and Variable with similar name resulting in error

Hey, I’m making a Claw Game. I have a fbx baseclaw mesh with script (with movement, inputs and states (and a kinematic rigidbody)) added and a fbx for the claw itself with the animations added.

link text

Here’s the code:

#pragma strict
public var clawSpeed : float = 2;
private var moveDirection : Vector3;
private var myTransform : Transform;

enum CharacterState
{
	Idle,
	Opening,
	Lowering,
	Closing,
	Closed,
	Raising,
	RaisedClosed,
	OpeningAgain,
}

var _characterState : CharacterState;

function Start () 
{
	myTransform = transform;
	//_characterState = CharacterState.Idle;
}

function Update ()
{
	moveDirection.x = Input.GetAxis("Horizontal");
	moveDirection.z = Input.GetAxis("Vertical");
	moveDirection.Normalize();
	myTransform.position += moveDirection * clawSpeed * Time.deltaTime;

	if (Input.GetKey(KeyCode.X))
	{
		switch (_characterState.Idle)
		{
			case _characterState.Opening:
			//play animation
			animation.Play("Opening");
			_characterState = CharacterState.Lowering;
			//change state
			break;
			
			case _characterState.Lowering:
			//play animation
			animation.Play("Lowering");
			_characterState = CharacterState.Closing;
			//change state
			break;
			
			case _characterState.Closing:
			//play animation
			animation.Play("Closing");
			_characterState = CharacterState.Closed;
			//change state
			break;
	
		}
	}
}

Here’s the error message:
“BCE0132: The namespace ‘’ already contains a definition for ‘CharacterState’.”

Objective: When X button is pressed one time plays “Opening” Animation, X button again plays “Lowering” Animation, X button again plays “Closing” and it keep going on.

Please help me!!

Well the error is correct: in this context the names must be unique.

This means you have to rename either this enum or the other CharacterState.

As I usually pluralise the names of my enums I would do this:

#pragma strict
public var clawSpeed : float = 2;
private var moveDirection : Vector3;
private var myTransform : Transform;

enum CharacterStates
{
    Idle,
    Opening,
    Lowering,
    Closing,
    Closed,
    Raising,
    RaisedClosed,
    OpeningAgain,
}

var _characterState : CharacterStates;

function Start () 
{
    myTransform = transform;
    //_characterState = CharacterStates.Idle;
}

function Update ()
{
    moveDirection.x = Input.GetAxis("Horizontal");
    moveDirection.z = Input.GetAxis("Vertical");
    moveDirection.Normalize();
    myTransform.position += moveDirection * clawSpeed * Time.deltaTime;

    if (Input.GetKey(KeyCode.X))
    {
       switch (_characterState.Idle)
       {
         case _characterState.Opening:
         //play animation
         animation.Play("Opening");
         _characterState = CharacterStates.Lowering;
         //change state
         break;

         case _characterState.Lowering:
         //play animation
         animation.Play("Lowering");
         _characterState = CharacterStates.Closing;
         //change state
         break;

         case _characterState.Closing:
         //play animation
         animation.Play("Closing");
         _characterState = CharacterStates.Closed;
         //change state
         break;

       }
    }
}