Search Unity

"Ghost" of GUI Text Displayed On Screen?

Discussion in 'Immediate Mode GUI (IMGUI)' started by AngrySc0rpi0n, Jan 6, 2015.

  1. AngrySc0rpi0n

    AngrySc0rpi0n

    Joined:
    Dec 21, 2014
    Posts:
    7
    Hello all!
    Thank you for taking your time to read this. I wanted to make a game sort of like Slender. So when you pick an object up (i.e. paper), it should add the number sort of like this:
    (none collected) 0/10
    (1 collected) 1/10
    etc.
    But I wanted it to display at the top of the screen the whole time. And when the "0" or "1" (etc.) changes, it sort of leaves a faded "0" in the background (picture below). How should I fix this? Here is my code:
    Code (JavaScript):
    1. var AntiBiotics : int;
    2. var ABSToWin : int = 10;
    3.    
    4. function OnTriggerEnter( other : Collider ) {
    5.     if (other.gameObject.tag == "AB") {
    6.         AntiBiotics += 1;
    7.         Debug.Log("An anti-biotic was picked up. Total anti-biotics = " + AntiBiotics);
    8.         Destroy(other.gameObject);
    9.     }
    10. }
    11.    
    12. function OnGUI() {
    13.     if (AntiBiotics < ABSToWin) {
    14.         GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), AntiBiotics + " Anti-Biotics");
    15.     }
    16.     else {
    17.         GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "All Anti-Biotics Retrieved!");
    18.        }
    19. }
    Thanks!
    AngrySc0rpi0n
     

    Attached Files:

  2. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    Are you certain you've only got this script on one object? It seems to me this is what you'd get if there were two of them. One would increase in value the other would stay at zero.

    Also I think you're using legacy gui, which is a different forum:
    http://forum.unity3d.com/forums/extensions-ongui.25/
     
  3. AngrySc0rpi0n

    AngrySc0rpi0n

    Joined:
    Dec 21, 2014
    Posts:
    7
    Thanks for replying. I found out that I had accidentally put the code on one of the parts of the map. Sorry for bothering.

    AngrySc0rpi0n
     
    Last edited: Jan 7, 2015