Javascript GUI and deathscript weird compiler errors

I’m new to unity coding but I was just trying to do my death script with the GUI for the lives too. I’m getting some errors that I don’t understand.

Assets/MyScripts/GUIcam.js(21,10): BCE0044: expecting (, found ‘OnGUI’.
Assets/MyScripts/GUIcam.js(21,18): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/MyScripts/GUIcam.js(22,1): BCE0043: Unexpected token: if.
Assets/MyScripts/GUIcam.js(22,16): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/MyScripts/GUIcam.js(23,59): BCE0044: expecting :, found ‘;’.

I understand what most of the error’s mean but if you look at the line numbers it gets confusing.

var icon1 : Texture2D;

var icon2 : Texture2D;
var icon3 : Texture2D;
var dead = false;
var Lives = 3;

function OnControllerColliderHit(hit : ControllerColliderHit){
if(hit.gameObject.tag == “Dead”){
dead = true;
if (Lives == 3){
Lives == 2;
}
if (Lives == 2){
Lives == 1;
}
if (Lives == 1){
Lives == 0;
}
}

function OnGUI (){
if (Lives == 3){
GUI.Box (Rect (10,10,100,100), GUIContent(icon3));
if (Lives == 2){
GUI.Box (Rect (10,10,100,100), GUIContent(icon2));
if (Lives == 1){
GUI.Box (Rect (10,10,100,100), GUIContent(icon1));
}
}
}
}
}

Future reference use the little binary 1/0 icon above the text box and insert your code snippet there so the code lays out appropriately. Easier to read.

It looks to me youre trying to place a function within a function which is not aloud in any language that I know of. Take the OnGUI() out of the collision function. The OnGUI() is like the Update for GUI. It updates a bunch a times per frame to keep constant up date. So place triggers within the OnGUI() and trigger those through the collision function. Keep in mind when you using the assignment operator ==/=, == is for if statements, variables within the () and then the information within the block, uses =. Ex: if(Lives == 3) { Lives = 2; }