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";
}
}
}
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/Manual/class-Camera.html
– BatangasYes, 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...
– Ridenhour