Error message in Health Script.

Hey guys,

I’m trying to make this health script but I cam across some errors. I was following a tutorial that I had saw, I think my problem is that the video is a little out dated. I was wondering if someone could help or fix these errors. Also here is the code if someone else wants it :slight_smile: also the script is in C#

using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {
public int Maxhealth = 100;
public int Curhealth = 100;

public float HealthBarLength
	void Start () {
	healthbarlength = Screen.width / 2;
	
	}
	
	// Update is called once per frame
	void Update () {
	Ajustcurrenthealth(0)
	
}

	void OnGUI() {
	 GUI.Box(new Rect(10, 10, HealthBarLength, 20), Curhealth + "/" + Maxhealth);
	
	}

	public void Ajustcurrenthealth(int adj) {
	curhealth +- adj
	
 HealthBarLength = (Screen.width /2) * (Curhealth / (float)Maxhealth);
	
	}
}

the errors I got were.
Assets/Scripts/Player Health.cs(9,12): error CS1519: Unexpected symbol `void’ in class, struct, or interface member declaration

Assets/Scripts/Player Health.cs(18,1): error CS1525: Unexpected symbol `}’

Assets/Scripts/Player Health.cs(28,16): error CS1525: Unexpected symbol `HealthBarLength’

Thanks for your help
Kind Regards
WarHawk.

public float HealthBarLength
	void Start () {

You forgot the semicolon.

So:

public float HealthBarLength;
	void Start () {

ok, fixed the first error message, Now just got the unexpected symbols to fix, any solutions?

Oh missed another Semi Colon. lol thats the second error fixed.

Fixed it and its all working. here is the code have fun.

using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {
public int Maxhealth = 100;
public int Curhealth = 100;

public float HealthBarLength;
    void Start () {
	HealthBarLength = Screen.width / 2;
	
	}
	
	// Update is called once per frame
	void Update () {
	AddJustCurrentHealth(0);
	
	}
	
	void OnGUI() {
	 GUI.Box(new Rect(10, 10, HealthBarLength, 20), Curhealth + "/" + Maxhealth);
	
	}

	public void AddJustCurrentHealth(int adj) {
	Curhealth += adj;
	HealthBarLength = (Screen.width /2) * (Curhealth / (float)Maxhealth); 
	}
}