Search Unity

Player Health

Discussion in 'Scripting' started by Student1499, Mar 26, 2012.

  1. Student1499

    Student1499

    Joined:
    Mar 13, 2012
    Posts:
    9
    Hello Guys

    Hereßs Dylan. I`ve got some problem with the Healthbar. There`s always a error code : Assets/Standard Assets/Scripts/Utility Scripts/PlayerHealth .cs(18,107): error CS1525: Unexpected symbol `;', expecting `)', or `,'.

    But I don`t get it. I used the same symbols. What`s wrong? Here?s the script:

    using UnityEngine;
    using System.Collections;

    public class PlayerHealth : MonoBehaviour {
    public int maxHealth = 100;
    public int curHealth = 100;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
    }

    void OnGUI (){
    GUI.Box (new Rect(10, 10, Screen.width / 2 / (maxHealth / curHealth)), curHealth + "/" + maxHealth;

    }
    }
     

    Attached Files:

    Last edited: Mar 26, 2012
  2. tigerfoot

    tigerfoot

    Joined:
    Nov 2, 2009
    Posts:
    132
    Well you're missing a ")" at the end of line 18

    Code (csharp):
    1.  
    2. GUI.Box (new Rect(10, 10, Screen.width / 2 / (maxHealth / curHealth)), curHealth + "/" + maxHealth);
    3.  
     
  3. Student1499

    Student1499

    Joined:
    Mar 13, 2012
    Posts:
    9
    Thanks, but now there´s a new erroc code :(


    Assets/Standard Assets/Scripts/Utility Scripts/PlayerHealth.cs(18,70): error CS1729: The type `UnityEngine.Rect' does not contain a constructor that takes `3' arguments



    Assets/Standard Assets/Scripts/Utility Scripts/PlayerHealth.cs(18,5): error CS1502: The best overloaded method match for `UnityEngine.GUI.Box(UnityEngine.Rect, string)' has some invalid arguments


    Assets/Standard Assets/Scripts/Utility Scripts/PlayerHealth.cs(18,5): error CS1503: Argument `#1' cannot convert `object' expression to type `UnityEngine.Rect'


    What do I need to do? I copy the right version from you in, but it now there´s a new error code
     
  4. Zethariel1

    Zethariel1

    Joined:
    Mar 21, 2012
    Posts:
    439
    Your Rect has only 3 properties -- 10, 10 and that Screen.width. Add the last, 4th one, and try and read the error code more in-peth -- they usually provide a specific thing you need to fix (in this case, only 3 arguments instead of 4 on the Rect)
     
  5. Wabsta

    Wabsta

    Joined:
    Mar 9, 2012
    Posts:
    2
    This is not how you are going to learn how to code..
    You should be able to debug stuff yourself. When I saw your code, I immediately saw that there was a ")" missing.

    Maybe you should be coding some simple applications first, do some tutorials to really understand how to code, and then dive into Unity.
     
  6. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    Always close what you've opened. { } ( ) < >
     
  7. tigerfoot

    tigerfoot

    Joined:
    Nov 2, 2009
    Posts:
    132
    You forgot [ ]. :)