I wanted to make a Start Race Counter thing in Unity, it was supposed to be two rotating rings with changing light inside of them and counter which shows “3,2,1,GO” and from my view it should work as it is now… but it does not and I have no idea why becouse it seem to be written good… I get this error although everything is assigned in Inspector as it should be:
NullReferenceException: Object reference not set to an instance of an object “line ~40”
Big thanks in advance ![]()
var start : boolean = false;
private var TurnLightOnOff : boolean = false;
private var Counter : float = 0;
private var Timer : float = 0;
private var TimerFull : float = 0;
var GO : Material;
var Num1 : Material;
var Num2 : Material;
var Num3 : Material;
var GreenLight : Material;
var PurpleLight : Material;
var OuterRing : GameObject;
var InsideRing : GameObject;
var Number : GameObject;
var BckLight : GameObject;
function Update () {
OuterRing.transform.Rotate (Vector3(-2,0,0));
InsideRing.transform.Rotate (Vector3(2,0,0));
if (start == true){
Timer += Time.deltaTime;
TimerFull += Time.deltaTime;
if (TimerFull >= 2){
if (Timer >= 1){
Counter ++;
Timer = 0;
}
}
}
switch (Counter){
case (1):
Number.renderer.material = Num3;
TurnLightOnOff = true;
return;
case (2):
Number.renderer.material = Num2;
TurnLightOnOff = true;
return;
case (3):
Number.renderer.material = Num1;
TurnLightOnOff = true;
return;
case (4):
Number.renderer.material = GO;
BckLight.renderer.material = GreenLight;
GameObject.Find("GameController").GetComponent(RaceSequencer).StartTimerEnd = true;
return;
}
if (TurnLightOnOff && TimerFull < 5){
BckLight.renderer.material = GreenLight;
if (Timer >= 0.5){
BckLight.renderer.material = PurpleLight;
TurnLightOnOff = false;
}
}
if (TimerFull >= 8){
transform.Translate (Vector3(0,0,-1));
Destroy (gameObject, 2);
}
}