x


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; 
     
     
 }       }
more ▼

asked Jun 05, 2011 at 12:19 AM

skyler396 gravatar image

skyler396
1 3 2 3

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

It seems the error is at:

(curHealth / (float))maxHealth;

the correct sintax is:

(curHealth / (float)maxHealth);

more ▼

answered Jun 05, 2011 at 12:42 AM

aldonaletto gravatar image

aldonaletto
57.6k 33 92 302

thanks alot im new at this the help is appreciated

Jun 05, 2011 at 09:16 PM skyler396
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jun 05, 2011 at 12:43 AM

Jessy gravatar image

Jessy
18.3k 208 178 293

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x207
x31

asked: Jun 05, 2011 at 12:19 AM

Seen: 4043 times

Last Updated: Jun 05, 2011 at 09:16 PM