- Home /
identifier expected
im trying to create a health bar using a tutorial i found but at "public void AdjustcurHealth (adj)" it says identifier expected
tutorial: http://wiki.unity3d.com/index.php/Health_Bar_Tutorial
help?
UPDATE: ok i got that fixed but now i got a new problem it says Unexpected symbol `/'
public class healthbar : MonoBehaviour {
private int maxhealth = 100;
public int curHealth = 100;
private float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
}
// Update is called once per frame
void Update () {
AdjustcurHealth(0);
}
void OnGUI (){
GUI.Box(new Rect(10,10, healthBarLength,20), curHealth.ToString "/" maxhealth.ToString);
}
public void AdjustcurHealth (adj) {
curHealth += adj;
if(curHealth > 0)
curHealth = 0;
if(curHealth > maxhealth)
curHealth = maxhealth;
if(maxhealth < 1)
maxhealth = 1;
healthBarLength = (Screen.width / 2) * (curHealth / (float)maxhealth);
}
}
Answer by AyAMrau · Sep 08, 2014 at 06:25 AM
When declaring a function you need to specify argument type:
public void AdjustcurHealth (int adj)
thanks but now i got a new problem it says Unexpected symbol `/'
Post full error messages, so we can see line numbers etc.
Change curHealth.ToString "/" maxhealth.ToString To:
curHealth.ToString() + "/" + maxhealth.ToString()
Your answer
![](https://koobas.hobune.stream/wayback/20220613162542im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
access user-entered ID across my mobile apps 0 Answers
Renderer on object disabled after level reload 1 Answer
How to put a health bar above enemy?C# 2 Answers