- Home /
Draw a GUIText behind a sprite
Hello,
I have a transparent sprite and I want to draw/write a GUIText behind this transparent sprite but I can't figure out how. I can sort the sprites with the Sorting Layer property of the Renderer but since the GUIText doesn't have a renderer I don't know how to do this. GUIText is always being drawn on top of everything.
Any help is appreciated.
Thanks!
Mario
Answer by Ngoc Ngo · Jun 27, 2014 at 06:03 AM
You could use a TextMesh instead of GUIText, then move it inside the scene with its Transform.
I tried that but now the Text $$anonymous$$esh is being drawn behind all the sprites. I need something I can completely control so I can set its Sorting Layer property just as I do with sprites.
Answer by Philsko · Oct 20, 2014 at 11:06 AM
If you use a TextMesh instead of GUIText as previously suggested you can control it's sorting layer by attaching this simple script to it:
using UnityEngine;
using System.Collections;
public class Layer : MonoBehaviour {
public string layerName;
// Use this for initialization
void Start ()
{
gameObject.renderer.sortingLayerName = layerName;
}
}
And then typing the layer name that you want to set it to in the inspector.
Your answer
![](https://koobas.hobune.stream/wayback/20220613152616im_/https://answers.unity.com/themes/thub/images/avi.jpg)