- Home /
Question by
beattonick · Aug 07, 2011 at 03:19 AM ·
c#syntax-error
health bar script error
i made this health script in c# and i always get the same error i tcheck my code like 100 time and i cant find my error plz help me.
code:
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.with / 2 /(maxHealth / curHealth), 20), curHealth + "/" + maxHealth);
}
}
Comment
Please reformat your code... select it, and click the 1010 button
Best Answer
Answer by AVividLight · Aug 07, 2011 at 03:59 AM
Hey Beattonick, Your code only had two problems, you were trying to declare variables in the wrong place, and you spelled width wrong.
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
void OnGUI() {
GUI.Box(new Rect(10, 10, Screen.width / 2 /(maxHealth / curHealth), 20), curHealth + "/" + maxHealth);
}
}
Your answer

Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
C# SetActive GameObject Array 2 Answers
counting in 3 different gui texts C# 0 Answers