Why my text is overwritten on previous one?
In my project there is a Main Camera and a Text UI on a Canvas and the below script. Why is my text get superpose on the previous text after pressing the spacebar and how can I avoid this behaviour?
using UnityEngine; using UnityEngine.UI;
public class PlayBoard : MonoBehaviour {
static Text message;
void Awake()
{
message = GameObject.Find("messageBox").GetComponent<Text>();
}
void Start()
{
message.text = "To begin press space bar";
}
void Update()
{
if (Input.GetKeyDown("space"))
{
message.text = "New Message should appear in clear";
}
}
}
Answer by pierrepm · Dec 28, 2016 at 04:44 AM
Finally I had to put the Unity Project to the recycle bin and start a new one using exactly the same script. This time the text field does act normally. I assumed that something was corrupted in the many lines of code Unity add to make a project work.
The camera has clear flags. If this is set to "Don't clear", the things that you drew will not be cleared when rendering the next frame. You probably played around with it and ended up with the value "Don't clear".
See here: https://docs.unity3d.com/ScriptReference/CameraClearFlags.html
or here: https://docs.unity3d.com/$$anonymous$$anual/class-Camera.html
Yes, thanks ScaniX, this is the right answer. The Clear Flags was set at Depth only. If I put it at either Skybox or Solid Color, everything works nicely. Bottom line don't mess-up with settings if you don't know what you are doing...
Your answer
Follow this Question
Related Questions
Using LookAt to look at a Vector3 not Transform 0 Answers
Multiple in game currencies 1 Answer
Why does Ctrl + ' not work for searching Unity Documentation? 0 Answers
The roll a ball script isn't working 3 Answers
Issues using two scripts. 1 Answer