- Home /
GameObject sortingOrder
Hi, i have made a script to create game object "texts" than added a guiText to it (working on a 2D game). Now i added an other game object (direct on the scene) that should hide the guiText, but i can't hide it the guiText still in front. I did a code to define "texts" layer order but doesn't work. here is the code, i don't know if it is the right solution.
Thanks for your suggestions
texts = new GameObject ("Texts");
texts.transform.position = Vector3 (0.5, 0.5, 0.0);
var sr : SpriteRenderer = texts.AddComponent(SpriteRenderer);
sr.sortingLayerName = "Default";
sr.sortingOrder = 1;
texts.AddComponent (GUIText);
texts.guiText.font = font;
texts.guiText.fontSize = 20;
Answer by kamgru123 · May 21, 2014 at 09:14 PM
GuiText is, well.. a gui, so it is always on top of other things. The easiest way to hide it is probably setting the enabled property to false:
texts.guiText.enabled = false;
Thanks for your answer, i have made something like that with (guiText.material.color.a) to fade it, but i was looking for a simple way without additional code.
Thanks again for your answers and precision.
could you use the 3D text on a separate camera ins$$anonymous$$d of GUI text?
i used a fade Out with the camera and that solved the problem in my case, but i think it's a real problem to deal with guiText in 2D games, and superimpose objects. Exemple, if we have 2 bloc notes with texts how can we make one in front of the other ?
Your answer
Follow this Question
Related Questions
Changing SpriteRenderer orderInLayer via scripting? 2 Answers
Draw a GUIText behind a sprite 1 Answer
making a GUI.Label displayed behind spawned gameobject 0 Answers
Tilemaps ignore sprite layers? 0 Answers