- Home /
Drawing a sprite box and then displaying text over it
I'm trying to figure out how to draw a sprite and then display text over it. I want to do something like this
Where I draw a sprite ontop of whatever is already in the background (and dimming the background) and then have configurable text ontop of it. My issue is the code to draw the image.
I'm using JS for my project if that helps at all. I tried looking in the references and around the GUI one's in particular, but couldn't find anything that seemed to fit my problem
Here is my current code
var hit : RaycastHit;
var menuOpen : boolean = false;
function OnGUI () {
if(menuOpen == true) {
GUI.Label(Rect(Screen.width / 2,Screen.height / 2,Screen.width,Screen.height),
"Line 1\nLine 2\nLine 3\nLine 4!");
}
}
function Start () {
}
function Update () {
if(Input.GetMouseButtonDown(0) &&
collider.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit,
Mathf.Infinity)) {
menuOpen = true;
}
}
Research:
GUI.Label()
GUIText
3D Text/Text$$anonymous$$esh
The third one lives in world space and therefore can be aligned the easiest. GUIText lives in viewport space, so you can use Camera.WorldToViewportPoint() to convert.
I ended up doing this function OnGUI () {
if(menuOpen == true) {
GUI.Label(Rect(0,0, Screen.width, Screen.height),"", "box");
GUI.Label (Rect (Screen.width/4, Screen.height/4-50, windowToDisplay.width, windowToDisplay.height),
windowToDisplay);
// exit button
if (GUI.Button (Rect (Screen.width/2 +150, Screen.height/4, exitToDisplay.width/4, exitToDisplay.height/4), exitToDisplay, invisibleStyle)) {
Application.Quit();
}
}
}
And it seems to work. Thanks