- Home /
Enemy AI Error
i followed this guys youtube tutorial but i got an error but he didn't, i always have problems with unity and i follow the tutorials 100% every step but i get these small annoying errors, any help with this script would be Great! ERROR: Assets/Enemy Health.js(1,11): UCE0001: ';' expected. Insert a semicolon at the end.
var health - 10;
var TakeDamage : boolean;
function OnTriggerEnter(other: Collider){
if(other.tag == "Player"){
TakeDamage = true;
}
}
function OnTriggerExit(other: Collider){
if(other.tag == "Player"){
TakeDamage = false;
}
}
function Update(){
if(TakeDamage){
if(Input.GetButtonDown("fire1")){
health - - 1;
}
}
}
if(health <- 1){
health - 0;
Destroy (gameObject);
}
Wait why are you saying var health - 10; ??? This should be var health = 10;
If you want to subtract, you need to use health-= 1 or whatever u want to subtract.
ahh thank you, the guy in the video had it as - 10 and i saw in the comments something about =10 but thank you very much!!
If you could, either accept my answer or the guy's answer below which is more detailed, so people will know this has been resolved.
Answer by Bunny83 · Jul 08, 2013 at 12:06 AM
Line 1 should be:
var health = 10;
Line 19 should be:
health -= 1;
Line 23 should be:
if(health <= 1){
And line 24 should be:
health = 0;
Also you have you brackets wrong. The last if-statement should be inside the Update function:
function Update()
{
if(TakeDamage)
{
if(Input.GetButtonDown("fire1"))
{
health -= 1;
}
}
if(health <= 1)
{
health = 0;
Destroy (gameObject);
}
}
You should indent your code to avoid such mistakes.
Your answer
Follow this Question
Related Questions
What is wrong with my script? 1 Answer
enemy mechanics script and declining health 1 Answer
Errors with script using Javascript. 2 Answers
Windows Script error upon opening a new javascript behavior script. 4 Answers
Problems with java script. 1 Answer