Using Enum in an if Statement

If I do the following:

#pragma strict

enum direction {up,down,left,right,none};

function Update () {
	if (direction == up) {
		transform.Translate(Vector3.forward);
	}
}

Then I get an error: Assets/Test.js(6,26): BCE0005: Unknown identifier: ‘up’.

How can I fix this?

enum defines a type, not a variable. What you have in your code is an enum type named direction, but you don’t have any instances (i.e. variables) of that type to compare against.

Try this instead:

#pragma strict

// It's good form to start enum names with a capital letter
enum Direction { up, down, left, right };

// Declare the variable and initialize it
var direction:Direction = up;

function Update() {
  if (direction == Direction.up)
  {
    // Go to town
  }
}