I’m making speech boxes in my game for NPCs but having a few issues.
I’m a unity rookie so dunno if this is the best way of doing it, but I create two GUI labels, one for the actual speech and one for the shadow underneath it (just black). I want the position of the speech box in the center of the NPC, which is why guiPosition is halved.
Here is my code:
//get size of text so we know shadow box size
Vector2 size = SpeechBox.CalcSize (new GUIContent (content));
//some code to set position of box above center of NPC
var guiPosition = Camera.main.WorldToScreenPoint (new Vector3 (transform.position.x, transform.position.y + 0.15f, 0));
guiPosition.y = Screen.height - guiPosition.y;
guiPosition.x = guiPosition.x - (size.x / 2f);
guiPosition.y = guiPosition.y - size.y;
//draw boxes
GUI.Label (new Rect (guiPosition.x + 3f, guiPosition.y + 3f, size.x, size.y), "", black);
GUI.Label (new Rect (guiPosition.x, guiPosition.y, size.x/2, size.y), content, SpeechBox);
The issue I’m having is when I try and get word wrap added to it. I don’t want the text to go over say… 300 pixels, and if it does it needs to move to the next line. I was thinking I could just add a min(size, 300) kind of thing to the code, but then the calcsize to get the shadow size wouldn’t work would it?
Just a little confused, am I in the right direction?