- Home /
What is the end of the script underlined?
The end of my script is underlined and shown as an error, hence not letting me go into game view. Thanks
using UnityEngine;
using System.Collections;
public class CarHealth : 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), curHealth + "/" + maxHealth),
}
Answer by Dave-Carlile · Jan 30, 2013 at 08:02 PM
The error messages given by the compiler are usually a pretty good indication of the problem.
You have a trailing comma instead of semicolon. Also you're missing the height parameter and closing ) for the call to Rect.
void OnGUI()
{
GUI.Box(new Rect(10, 10, Screen.width / 2 / (maxHealth / curHealth), ???height???),
curHealth + "/" + maxHealth);
}
It was originally a semi-colon but told me that it was unexpected and a , was expected? The error message says that the } on line 5 in this format is unexpected, but when I take it away it shows other errors.
You also have only a single closing parentheses, which closes the Rect call. You need one to close Box too. See changes in my answer.
Hmm, actually it gets even worse. You're also missing the height parameter in Rect.
I changed the script completely and found another that worked. Thanks for tips though, will mark as correctly answered.