Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Dethl · Feb 22, 2011 at 01:26 AM · syntax-erroruce0001

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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;
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dethl · Feb 22, 2011 at 01:33 AM 0
Share

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.

avatar image · Feb 22, 2011 at 02:21 AM 0
Share

No worries! If this fixes your problem, please mark it as correct by clicking the tick to the left of the answer.

avatar image Dethl · Feb 22, 2011 at 04:11 AM 0
Share

Ok i Did it, Thanks! :D

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Lerpz tutorial multiple errors.HELP!!!! 4 Answers

Editing the jumppad from the 3rd person tutorial 2 Answers

Scripting Error when drawing texture to custom window; What am I doing wrong? 1 Answer

Semicolon? WHAT? HELP ME! 1 Answer

Making it display a Gui 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges