I made a script in Unity to any object(enemy) such that when I click it it's health decreases,I found the tutorial on YouTube and it works for him. I re-checked the code and I even typed the whole code again but still doesn't work It just shows health = 100 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I made a script in Unity to any object(enemy) such that when I click it it's health decreases,I found the tutorial on YouTube and it works for him. I re-checked the code and I even typed the whole code again but still doesn't work It just shows health = 100

Game development

3rd Feb 2017, 3:49 AM
TheSainMan
TheSainMan - avatar
8 Answers
+ 7
Unless we see the code, we can't really help...
3rd Feb 2017, 3:56 AM
Jafca
Jafca - avatar
+ 7
Try using health instead of Health in the function because variable names are case-sensitive
3rd Feb 2017, 4:05 AM
Jafca
Jafca - avatar
+ 7
Make sure player health and enemy health aren't the same variable. Try playerHealth and enemyHealth
3rd Feb 2017, 4:40 AM
Jafca
Jafca - avatar
+ 7
BTW it's JavaScript, not Java 😀
3rd Feb 2017, 4:46 AM
Jafca
Jafca - avatar
+ 5
make sure the box collider on both objects are in the right places
11th Feb 2017, 4:54 PM
Eric Kershner
Eric Kershner - avatar
+ 1
Ok I'll type.....wait a bit
3rd Feb 2017, 3:57 AM
TheSainMan
TheSainMan - avatar
0
It's actually Java I think #pragma strict var health = 100; function ApplyDamage (TheDamage:isn't) { Health-=TheDamage; }
3rd Feb 2017, 4:01 AM
TheSainMan
TheSainMan - avatar
0
No I typed in health,in both player and enemy,it's just a typo in my iPad
3rd Feb 2017, 4:28 AM
TheSainMan
TheSainMan - avatar