Search Unity

Question about Leveling System

Discussion in 'Scripting' started by RaysFan, Aug 27, 2012.

  1. RaysFan

    RaysFan

    Joined:
    Jul 5, 2012
    Posts:
    27
    Ok, I have been following tutorial on leveling system, and I have some errors. Error line 22: Unexpected Symbol '}'. Line 34: Parsing Error. Here is script:

    using UnityEngine;
    using System.Collections;

    public class PlayerLevelSystem : MonoBehaviour {

    private int curLevel = 1;
    private int maxLevel;

    private int curExp = 0;
    private int maxExp = 100;

    // Use this for initialization
    void Start ()
    {

    }

    // Update is called once per frame
    void Update ()
    {
    if(curExp >= maxExp)
    }
    curExp=100;
    curLevel++;

    }
    void OnGUI()
    {
    GUILayout.BeginArea(new Rect(20,50,40,20), curexp + "/" + maxExp);
    GUILayout.BeginArea(new Rect(20,50,40,20), "Level:" + curLevel);
    }
     
  2. Beennn

    Beennn

    Joined:
    Sep 11, 2010
    Posts:
    373
    Looks like where you have
    Code (csharp):
    1. // Update is called once per frame
    2. void Update ()
    3. {
    4. if(curExp >= maxExp)
    5. }
    6. curExp=100;
    7. curLevel++;
    it should be
    Code (csharp):
    1. if(curExp >= maxExp) {
    2.  
    3. curExp=100;
    4. curLevel++;
    5.  
    6. }
    instead

    you also need to remove the } on line 26, and place it at the end of the script, your cutting out
    Code (csharp):
    1. void OnGUI()
    2. {
    3. GUILayout.BeginArea(new Rect(20,50,40,20), curexp + "/" + maxExp);
    4. GUILayout.BeginArea(new Rect(20,50,40,20), "Level:" + curLevel);
    5. }
    where you currently have it placed.

    so this should work
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerLevelSystem : MonoBehaviour {
    5.  
    6. private int curLevel = 1;
    7. private int maxLevel;
    8.  
    9. private int curExp = 0;
    10. private int maxExp = 100;
    11.  
    12. // Use this for initialization
    13. void Start ()
    14. {
    15.  
    16. }
    17.  
    18. // Update is called once per frame
    19. void Update ()
    20. {
    21. if(curExp >= maxExp) {
    22.  
    23. curExp=100;
    24. curLevel++;
    25.  
    26. }
    27.  
    28.  
    29. }
    30.  
    31.  
    32.  
    33. void OnGUI()
    34. {
    35. GUILayout.BeginArea(new Rect(20,50,40,20), curexp + "/" + maxExp);
    36. GUILayout.BeginArea(new Rect(20,50,40,20), "Level:" + curLevel);
    37. }
    38.  
    39. }
     
    Last edited: Aug 27, 2012
  3. pus2meong

    pus2meong

    Joined:
    May 3, 2012
    Posts:
    83
    You bracket is wrong at "if" statement
     
  4. RaysFan

    RaysFan

    Joined:
    Jul 5, 2012
    Posts:
    27
    Ok, the script worked, but it seems to be throwing at me no GUI. The EXP text shows, but no GUI, and level isn't even there. could you show me what I am doing wrong?
     
  5. Beennn

    Beennn

    Joined:
    Sep 11, 2010
    Posts:
    373
    You need to create the graphics for the UI yourself.
    You can't see the the level?
     
  6. RaysFan

    RaysFan

    Joined:
    Jul 5, 2012
    Posts:
    27
    So would I do a GUI.box? or what? Because someone said to use GUILayout.BeginArea. And yes, I cant see the level.
     
  7. Beennn

    Beennn

    Joined:
    Sep 11, 2010
    Posts:
    373
    You can have some fun with the GUI in unity, you should check out the reference page here: GUI Scripting Guide
     
  8. RaysFan

    RaysFan

    Joined:
    Jul 5, 2012
    Posts:
    27
    ugh..I need to know whether I need GUI.box or what? Ugh.
     
  9. Beennn

    Beennn

    Joined:
    Sep 11, 2010
    Posts:
    373
    You don't need one, you could use one.
     
  10. RaysFan

    RaysFan

    Joined:
    Jul 5, 2012
    Posts:
    27
    Got it fixed thanks to a friend of mine! And thanks for the help as well!