I’m watching youtube tutorials from http://www.youtube.com/user/BurgZergArcade and already on first tutorial (for health bar) i have problem with scripting. The code i’m typing is:
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 (10,10,Screen.width/2/(maxHealth/curHealth),20), curHealth + “/” + maxHealth);
}
}
After it, on compailer errors which comes are:
Assets/Scripts/PlayerHealth.cs(19,17): error CS1014: A get or set accessor expected
and:
Assets/Scripts/PlayerHealth.cs(18,14): error CS0547: `PlayerHealth.OnGUI’: property or indexer cannot have void type
Can anyone please help me? I’m using x64 Win7 and i just can’t find problem :
Please and thank you
I can’t believe that I didn’t see that. I was looking at it 2 hours, searching for problem and still nothing. Cannot thank you more Sorry for my stupid question
Those errors should take all of 3 seconds for a beginner programmer to understand the problem. It outright says you are trying to use OnGUI as a property.
Read the errors, research the errors, and you’ll save yourself the two hours next time.
I politely disagree. It’s an oversight, and the error, while to a more experienced developer may seem straightforward, is obtuse to explaining that the dev is forgetting something in the code.