I’m learning Javascript, and I am creating a Player Health script. Basically, I declared my health variable as a public var Health = 100; and my max health possible as public var MaxHealth = 100;. Here is my code:
#pragma strict
public var Health = 100;
public var MaxHealth = 100;
function Start () {
Health = 100;
}
function Update () {
if(Health <= 0)
{
Die();
}
if(Health >=101)
{
Health = 100;
}
function Die()
{
GameObject.Destroy();
}
}
You can see that if the var Health is less than or equal to zero, the player dies. I am getting these errors:
Assets/Custom Scripts/Player Health.js(25,10): BCE0044: expecting (, found ‘Die’.
Assets/Custom Scripts/Player Health.js(25,15): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/Custom Scripts/Player Health.js(28,29): BCE0044: expecting :, found ‘;’.
Please help me, I’m new to Javascript! 
In function Die, use Destroy(gameObject) instead of GameObject.Destroy()
function Die(){
Destroy(gameObject);
}
BTW, use pair to wrap the code.
so what should the final script look like?
Main issue is you forgot the closing brace on your update function.
personal preference, but i’ve found it helps with things like closing brackets… always drop the ‘{’ after the function name and parameters to the next line, so
function Update()
{
}
instead of
function Update() {
}
then if you are rigorous with following your indentation you should always spot this kind of small mistake:
function Update ()
{
if(Health <= 0)
{
Die();
}
if(Health >=101)
{
Health = 100;
}
// missing }
function Die() // this function is currently inside update()
{
GameObject.Destroy();
}
} // extra }
(just copied from the OP no corrections, just formatting)
incorrect bracketing is one of the mistakes which cause all kinds of errors which point to other lines than where the mistake is since the compiler is following bad instructions… if the errors have lots of "expecting"s check your brackets and braces.