Need a little help with a switch statement

Hi all, I am getting an error in the following script that says ‘Operator == cannot be used with a left hand side of type ‘System.Type’ and a right hand side of type State’. The error occurs at the beginning of the switch statement.

Here is the script:

import System.Collections.Generic;
enum State{open, close, inbetween}
var openSound : AudioClip;
var closeSound : AudioClip;

var parts : GameObject[];
var defaultColors : Color[];
var particleEffect : GameObject;
var go : GameObject;
var maxDistance : float;
var player : GameObject;
var mytransform : Transform;
var inUse = false;
var MyGUI;
var used = false; //track if the chest has been used or not
var x : int;

var cnt : int;
var glow : boolean;
var state = State;

var loot : List.<Item>;
var ItemGenerator : ItemGenerator;
//[RequireComponent(typeof(BoxCollider))]
//[RequireComponent(typeof(AudioSource))]

//public State state;
function Start() {
loot = new List.<Item>();
mytransform = transform;
state = Chest.State.close;

particleEffect.active = false;

defaultColors = new Color[parts.Length];

if(parts.Length > 0)
for(cnt = 0; cnt < defaultColors.Length; cnt++)
defaultColors[cnt] = parts[cnt].renderer.material.GetColor("_Color");
}

function Update () {
if(!inUse)
return;

if(player == null)
return;

if(Vector3.Distance(mytransform.position, player.transform.position) > maxDistance && !inUse)
MyGUI.chest.ForceClose();
//SendMessageUpwards("CloseChest");
}

function OnMouseEnter() {
Debug.Log("Enter");
HighLight();
}

function OnMouseExit() {
HighLight();
}

function OnMouseUp() {
go = GameObject.FindGameObjectWithTag("Player");
if(go == null)
return;

if(Vector3.Distance(transform.position, go.transform.position) > maxDistance)
return;
}

switch (state) {  <<ERROR OCCURS HERE
case State.open:
	state = Chest.State.inbetween;
	//StartCoroutine("Close");
	ForceClose();
break;

case State.close:
	if(MyGUI.chest != null) {
	MyGUI.chest.ForceClose();
	}
	state = Chest.State.inbetween;
	StartCoroutine("Open");
break;

}
//if(state == Chest.State.close)
//Open();
//else
//Close();

function Open() {
MyGUI.chest = this;
player = GameObject.FindGameObjectWithTag("Player");
inUse = true;
animation.Play("");
particleEffect.active = true;
AudioClip.Play("openSound");
if(!used)
PopulateChest();//5
//yield return new WaitForSeconds(2);

state = Chest.State.open;
//SendMessageUpwards("PopulateChest", 5); //gameObject
SendMessageUpwards("DisplayLoot"); //gameObject

}

function PopulateChest() {
//chest = go;
for(cnt = 0; cnt < x; cnt++) { //x
loot.Add(ItemGenerator.CreateItem());
//loot[cnt].Name = "I:" + Random.Range(0, 100);
used = true;
}

}

function Close() {
player = null;
inUse = false;
//SendMessageUpwards.DONT_REQUIRE_LISTENER("PopulateChest", 5);

animation.Play("");

particleEffect.active = false;
AudioClip.Play("closeSound");
//yield return new WaitForSeconds(2);

state = Chest.State.close;

if(loot.Count == 0)
Destroy(gameObject);
}

function ForceClose() {
SendMessageUpwards("CloseChest");

StopCoroutine("Open");
StartCoroutine("Close");
}

function HighLight() {
if(glow) {
if(parts.Length > 0)
for(cnt = 0; cnt < defaultColors.Length; cnt++)
parts[cnt].renderer.material.SetColor("_Color", Color.yellow);
}

else {
if(parts.Length > 0)
for(cnt = 0; cnt < defaultColors.Length; cnt++)
parts[cnt].renderer.material.SetColor("_Color", defaultColors[cnt]);
}
}

This is only the second time I have had to use a switch statement and I cannot figure out why its throwing me this error. Can someone take a quick look and see what I’m doing wrong? Thank you!

You’ve defined “state” as a type, rather than saying what it is.

var state = State.open;

Or:

var state : State;