Unknown Identifiers for declared variables?

I am having problems with variables that, although I am declaring them, I am getting an “Unknown Identifier” error. The errors are in this code:

enum type {runner,attacker,circler,wanderer}

function Start ()
{
	var spawner  = transform.parent.gameObject;
	var group  = spawner.SnakeSpawn.group;
	var gravity : float = spawner.SnakeSpawn.gravity;
	var speed : float = spawner.SnakeSpawn.speed;
	var rotationSpeed : float = spawner.SnakeSpawn.rotationSpeed;
	var distance : float = spawner.SnakeSpawn.distance;
	var snakeType = spawner.SnakeSpawn.type;
}

function Update () {

	switch(snakeType)

		{
	            //[...]
		}
	
	
}
function OnCollisionEnter ()
{
	if ((spawner.SnakeSpawn.color) == (group.SnakeGroup.correct))
	{
		//Make door 'result' true
		group.SnakeGroup.goGone = true;
		Destroy(gameObject);
	}
	else if (spawner.SnakeSpawn.color != group.SnakeGroup.correct)
	{
		group.SnakeGroup.goGone = true;
		Destroy(gameObject);
	}
	else if (group.SnakeGroup.goGone)
	{
		Destroy(gameObject);
	}
}

The errors are:

  1. in the switch statement
  2. in the first “if” statement (both variables in condition)
  3. in both “else if” statements (all three variables in condition)
  4. at “group.SnakeGroup.goGone” (both times)

None of your variables are available outside the Start function, so they can only be used in the Start function. You have to declare variables outside functions if you want them to be available in other functions.

You should declare all variables that will be used by two or more function “on top of the script”, so they will be declared as “global” variables in that particular script. Then you could set the variables you want in the Start function. Example your spawn variable is declared in the Start function and cannot be read/or written to by other functions, you should to as follows (with all of your, must be used be others variables):

var spawner : GameObject;

function Start() {
  spawner = transform.parent.gameObject;
}

bottomline: do as my example with all of your variables:

var spawner : GameObject;
var group;
var gravity : float;
var speed : float;
var rotationSpeed : float;
var distance : float;
var snakeType;

function Start ()
{
    spawner  = transform.parent.gameObject;
    group  = spawner.SnakeSpawn.group;
    gravity = spawner.SnakeSpawn.gravity;
    speed = spawner.SnakeSpawn.speed;
    rotationSpeed = spawner.SnakeSpawn.rotationSpeed;
    distance = spawner.SnakeSpawn.distance;
    snakeType = spawner.SnakeSpawn.type;
}