- Home /
I need help with this script, where are the errors?
I cant seem to find the errors in my script could someone point them out so I can fix them?
Code :
#pragma strict
var damageDelay = 3.0;
var Spikes : boolean;
var Jab : AudioClip;
function Start () {
}
function Update () {
if(InSpikes = true){
yield WaitForSeconds(damageDelay);
Health.HP = Health.HP - 1;
audio.PlayOneShot(Jab);
}
}
function OnTriggerEnter (){
InSpikes = true;
}
function OnTriggerExit (){
InSpikes = false;
}
I apologize in advance for the terrible script I threw this together
Answer by ideaman · Sep 27, 2013 at 04:31 AM
In line 15 you should write:
if(InSpikes == true){ instead of if(InSpikes = true){
when you checking if something is true you should use ==
when you assign a value you use =
Daniel
Wow thanks cant believe I missed that I have been out of the game for a couple weeks.
Answer by Kiloblargh · Sep 27, 2013 at 05:36 AM
You declared the variable as "Spikes" and then refer to it in the rest of the script as "InSpikes". It should be inSpikes, because variables should start with lowercase letters.
Also-
if (inSpikes)
does the same thing as saying
if (inSpikes == true)
and
if (!inSpikes)
does the same thing as
if (inSpikes == false)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Unity 4.0.0f7 GetThreadContext failed 2 Answers
Spawn Script Issue 0 Answers
Vehicle Script Help 1 Answer
Parsing Error at End of Script? 0 Answers