- Home /
error CS1525: Unexpected symbol `)'
using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour { public int maxHealth = 100; public int curHealth = 100;
public float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
GUI.Box(new Rect(10, 10, Screen.width / 2 / (maxHealth / curHealth), 20), curHealth + "/" + maxHealth);
}public void AddjustCurrentHealth(int 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 aldonaletto · Jun 05, 2011 at 12:42 AM
It seems the error is at:
(curHealth / (float))maxHealth;
the correct sintax is:
(curHealth / (float)maxHealth);
Answer by Jessy · Jun 05, 2011 at 12:43 AM
Your last ) needs to move after the variable name. The console tells you what line numbers your error is on.
Screen.width is an int, by the way, so you shouldn't do integer division with it, like you are.
healthBarLength = Screen.width * .5F * (curHealth / (float) maxHealth);
But the parentheses aren't helping you at all, and if you get rid of them, you don't need an explicit cast.
healthBarLength = Screen.width * .5F * curHealth / maxHealth;
You may want to store Screen.width .5F / maxHealth* as a variable to avoid an extra multiplication and a division all the time.
Your answer

Follow this Question
Related Questions
Need help on Transportation errors 1 Answer
Unable To Find Solution For Errors 1 Answer
Unexpected symbol error in code 2 Answers
Really Simple C# Errors I Can't Figure Out 1 Answer
Unexpected symbol `model' 4 Answers