Does Anyone Know Why It Can Not Find My Var.

#pragma strict

var spawn1 : GameObject;
var spawn2 : GameObject;
var spawn3 : GameObject;
var spawn4 : GameObject;
var blueBallSmall : GameObject;
var blueBall : GameObject;
var blueBallLarge : GameObject;
var yellowBallSmall : GameObject;
var yellowBall : GameObject;
var yellowBallLarge : GameObject;
var redBallSmall : GameObject;
var redBall : GameObject;
var redBallLarge : GameObject;
var greenBallSmall : GameObject;
var greenBall : GameObject;
var greenBallLarge : GameObject;
var pinkBallSmall : GameObject;
var pinkBall : GameObject;
var pinkBallLarge : GameObject;
var purpelBallSmall : GameObject;
var purpelBall : GameObject;
var purpelBallLarge : GameObject;
var playerObject : GameObject;
var numberOfBunces = 0;
var needNumber = true;
var needSpawnPoint = true;
var spawnPoint;

function Start () {
if(needSpawnPoint == true){
var numberSpawnForPoint = Random.Range(1,5);	
Debug.Log(numberSpawnForPoint);
needSpawnPoint = false;
}
if(needNumber == true){
var numberBall = Random.Range(1,7);	
Debug.Log(numberBall);
needNumber = false;
}
var player : GameObject = gameObject.FindGameObjectWithTag("Player");
}

function Update () {
var scripting : GUIBounce = playerObject.GetComponent(GUIBounce);
numberOfBunces = scripting.noBounces;
if (numberOfBunces == 0){
	if (numberSpawnForPoint == 1){
		spawnPoint = spawn1;
	}
	else if (numberSpawnForPoint == 2){
		spawnPoint = spawn2;
	}
		else if (numberSpawnForPoint == 2){
		spawnPoint = spawn3;
	}
		else{
		spawnPoint = spawn4;
	}
}
}

it say’s that it can not find the var numberSpawnForPoint and public does not work can anyone help Thanks.

if I read correctly and understand correctly the variable you are refering to is only declared for that function and such does not exist to the other function.

to fix declare it globally

You are declaring ‘numberSpawnForPoint’ inside Start(). That means that it scope is just inside Start(). It comes into existence when you enter Start() and goes away when you exit start. The way to solve this is put this at the top of the file:

 private var numberSpawnForPoint;

I made it ‘private’ since you don’t need it to show up in the inspector. Then in Start() do:

 numberSpawnForPoint = Random.Range(1,5); 

Note the line does not have the ‘var’ of the original line.