Unexpected text appears using UI
I'm creating my very first game in which a ball is repairing objects. When I enter the collider of an object, a text appears under the simple minimap saying "In repair..." with a countdown and when the countdown is over, it turns into "REPAIRED". This is all good, but when I enter the collider for the 2nd time before OR after it is repaired, the following strange, upside-down text appears for a very brief time (couple of frames maybe): No text should appear here.
In comparison, this is what I should normally see (and I do see it after a frame, please disregard the glowing element, it is not connected to the text): I paste the script controlling the behavior of the text here :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class RepairText : MonoBehaviour {
public Text repairText; //reference to the text comp
public GameObject metaBallTrigger; // reference to the GO trigger
public SpinningSiren refSiren; //reference to the script attached to the player
public GameObject collectible; //reference to the collectible GO
public RepaireCollectible repColText; //reference to the script attached to the collectible
void Start ()
{
repairText.enabled = false;
refSiren = metaBallTrigger.GetComponent<SpinningSiren>(); //using script from the trigger GO
repairText.text = "";
}
void Update ()
{
if (refSiren.inRepair) //if inside the collider of the collectible
{
repColText = refSiren.repairCollectible;
repairText.enabled = true; //text appears
if (!repColText.repaired) //if it is not repaired yet
{
repairText.text = "In repair... " + ((int)repColText.timer).ToString(); //float timer is converted to int to display conventional 1, 2, 3, etc.
}
else
{
repairText.text = "REPAIRED"; //if repaired, display this
}
}
else //if not in repair
{
repairText.text = "";
repairText.enabled = false;
}
}
}
To me, it looks like some kind of memory garbage, but I have no idea. I tried to initialize the text in the beginning and set it back to "" if unused, but I am new to unity, so I don't know if I was right to do so. Has anyone seen anything like this?
Answer by rTECH · Jan 24, 2016 at 08:53 AM
I captured two other, with different text. This time, I flipped the image and used a readable font. The text is different before and after I repaired the collectible. This is still very bizarre. Help is much appreciated :) before: after:
Your answer
![](https://koobas.hobune.stream/wayback/20220612061405im_/https://answers.unity.com/themes/thub/images/avi.jpg)