I get an unknown identifier on line 23 and 24. The error is here
else if (timerValue <= 0 && timerCoolDown > 0){
timerCoolDown -= Time.deltaTime;
This is my code:
private var lightSource : Light;
var soundTurnOn : AudioClip;
var soundTurnOff : AudioClip;
var timerStartValue : float = 30;
var timerValue : float = 0;
var timerCoolDownStart : float = 40;
var timerCoolDownValue : float = 0;
function Start () {
lightSource = GetComponent(Light);
timerValue = timerStartValue;
timerCoolDownValue = timerCoolDownStart;
}
function Update () {
if (Input.GetKeyDown(KeyCode.F) && timerValue > 0) {
ToggleFlashLight();
}
if (timerValue > 0 && timerCoolDownValue >= timerCoolDownStart){
timerValue -= Time.deltaTime;
}
else if (timerValue <= 0 && timerCoolDown > 0){
timerCoolDown -= Time.deltaTime;
lightSource.enabled = false;
audio.clip = soundTurnOff;
audio.Play();
}
else{
timerValue = timerStartValue;
timerCoolDownValue = timerCoolDownStart;
}
}
function ToggleFlashLight () {
lightSource.enabled=!lightSource.enabled;
//Audio
if (lightSource.enabled) {
audio.clip = soundTurnOn;
} else {
audio.clip = soundTurnOff;
}
audio.Play();
}
whats with the
– Benproductions1else ifat the start of your code, thats should cause some errors!Also you re using
– Benproductions1timerCoolDownValueand then you start usingtimerCoolDown, which is not defined. Either define it, or change it, thats should solve your problemelse if (timerValue <= 0 && timerCoolDown > 0){ timerCoolDown -= Time.deltaTime; Is where the errors are sorry didnt make that clear
– killerbatNever mind, it was your weird layout
– EliteMossy@EliteMossy: No, the first two lines are not part of the code. I also thought it was something odd like that but as @killerbat commented, it was just to highlight where in the code the line 23 and 24 is.
– Statement