I found a health bar tutorial and it is not working for me

using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;

// Use this for initialization
void Start () {

// Update is called once per frame
void Update () {

void OnGui() {
	GUI.Box(new Rect(20, 20, Screen.width / 2 / (maxHealth / curHealth), 20), curHealth + "/" + maxHealth);


This is the code I used and it was not working… It will not display the health bar… I am super new to unity and very dumb at coding.

The problem lies in the naming of the OnGUI method.

In C# casing is important, so OnGui is actually different from OnGUI.

Therefore just rename your method to OnGUI and everything should work fine.