Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

ongui label overlap issue

Discussion in 'Scripting' started by louis66, Mar 17, 2015.

  1. louis66

    louis66

    Joined:
    Feb 5, 2015
    Posts:
    6
    all i am trying to do is add 10 when the button is clicked, but to have the gui show up i need to click a button that calls the method voidclicked. I would like the gui to show when the program starts which is when i try to add it in void start but once i do when i click the button to add 10 it creates a new label or something because you can tell there is now more than 1 set of numbers on the same spot.

    it all works perfect until i make the bool true in start up and im wondering if this is possibly a bug?

    Code (CSharp):
    1.  
    2.     public bool test =  false;
    3.     public int moneyvalue = 0;
    4.     public int MPS = 1;
    5.  
    6.     void Start () {
    7.         test = true; //this line is what messes it all up
    8.         InvokeRepeating ("moneypersecond", 1, 1f);
    9.     }
    10.  
    11.     void moneypersecond(){
    12.         moneyvalue += MPS;
    13.         }    
    14.      
    15.     public void clicked(){
    16.         if (test  == false) {
    17.             test  = true;
    18.         }
    19.     }
    20.  
    21.     void OnGUI () {
    22.         if (test) {
    23.             GUI.Box (new Rect (20, 21, 150, 30),"");
    24.             GUI.Label (new Rect (25, 25, 150, 30), moneyvalue.ToString ());
    25.           if(GUI.Button (new Rect (110, 140, 80, 30), "+10)){
    26.                  moneyvalue +=10;
    27.            }
    28.        }
    29.    }
    30.  
    31. }
     
    Last edited: Mar 17, 2015
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Have you got the script enabled on more than one object in the scene?
    ps. line 25 is missing a "
     
    louis66 likes this.
  3. louis66

    louis66

    Joined:
    Feb 5, 2015
    Posts:
    6
    thanks that worked didnt realize that would mess it up thanks .