- Home /
insert semicolon
I am getting an error on line 42 saying to insert a semicolon at the end but I am not sure where.
function Start () {
healthRegen();
}
function Update () {
healthtext.text = curHealth + " / " + maxHealth;
if(curHealth < 0 ) {
curHealth = 0;
}
if(curHealth > 100) {
curHealth = 100;
}
void OnCollisionEnter(Collision);
{
if(collider.tag == "enemy")
{
/
}
}
}
function healthRegen () {
for(i=1;i>0;i++) {
yield WaitForSeconds(1);
if(curHealth < maxHealth) {
curHealth++;
}
}
}
I am not 100% sure but I don't think you can call OnCollisionEnter the way you did. It happens when the player collides. Try noting that line out with double slash // and seeing if it works :)
Answer by Em3rgency · Jun 25, 2013 at 06:50 AM
You have a single / in line 42. Remove it.
EDIT: additionally, in your code void OnCollisionEnter(Collision); should be void OnCollisionEnter(Collision collider);
I think they put that there as an indication 'this is line 42' but I am not 100% sure :)
Answer by Armand · Jun 25, 2013 at 07:00 AM
You have a lone "/" on line 42, delete it or comment it out by changing it to "//". Also, you have an extra ";" on line 36, delete that one as well.
It would also be a good idea to try and be consistent with the way you use braces and indentations. It's technically not necessary, but trust me, when you start writing more code you'll be glad if you've made it more readable. Here's an example of cleaner indentation and bracing:
function exampleFunction() {
var a = 0;
var b = 1;
var c = 0;
if (a > b) {
b = a;
if (a > c) {
c = a;
}
}
return b;
}
Answer by fafase · Jun 25, 2013 at 07:02 AM
Ok couple of things yu have done wrong.
First, it is not void OnCollisionEnter(Collision) but
function OnCollisionEnter(col:Collision){}
since you are in UnityScript
Also, the OnCollisionEnter should be outside the Update, you cannot declare a function inside another function. This is programming basic, not only in Unity
And finally, remove the single /