- Home /
Problem with my Hack and Slash tutorial Health bar script
Well the problem is: I have been following the Hack and Slash Tutorial, i'm at Health Bar 2/2, but there is a problem with my Scrip, get the following errors:
Error 1 Only assignment, call, increment, decrement, and new object expressions can be used as a statement C:\Users\Zelda-Maniack\videogame\game1\OrbS\Assets\Scripts\PlayerHealth.cs 31 21 OrbS
Error 2 ; expected C:\Users\Zelda-Maniack\videogame\game1\OrbS\Assets\Scripts\PlayerHealth.cs 31 21 OrbS
Both of them are in the same line and in the adj statement:
curHealth ++ adj;
Here is the script, When i delete that line all the errors disappear.
using UnityEngine; using System.Collections;
public class PlayerHealth : MonoBehaviour { public int maxHealth = 100; public int curHealth = 100;
public float healthBarLenght;
// Use this for initialization
void Start ()
{
healthBarLenght = Screen.width / 2;
}
//Update is called once per frame
void Update()
{
AddJustCurrentHealth(0);
}
void OnGUI()
{
GUI.Box(new Rect(10, 10, healthBarLenght, 20), curHealth + "/" + maxHealth);
}
public void AddJustCurrentHealth(int adj)
{
curHealth ++ adj;
healthBarLenght = (Screen.width / 2) * (curHealth /(float)maxHealth);
}
Please help me I'm getting a little desperate XD.
Answer by · Feb 22, 2011 at 01:29 AM
Looking at this line of code:
curHealth ++ adj;
I believe you want to add the value of adj
to the value of curHealth
, and store it back into curHealth
. For C-derivative code, use +=.
i.e.
curHealth += adj;
wow Thanks that worked! :D you're great, i got confused with c++ and JavaScript XD i haven't even learned enough of those two and I'm already into this... i think I'll go step by step.
No worries! If this fixes your problem, please mark it as correct by clicking the tick to the left of the answer.