- Home /
How to create a GUI Text when reaching a point
Hello everyone, i'm currently working on a horror game and i've being searching for an idea everywhere, such as: Google, Youtube, Unity Answers etc...
Here's my idea: How to create a GUI text when reaching a place.
What I actually mean is not an object, I mean the position (for ex: X:534, Y:311, Z: 734)
If you guys have any kind of script that are vaild for my idea OR if you find a link that sounds familiar to this post, please post them below, I would apreciate anything (that works, of course)
Thanks!
~crusherxman
Answer by robertbu · Mar 02, 2013 at 09:26 PM
There's lots of ways of doing this, and what you want will depend on your game. Here is a starter script. Attach it to an object (even an empty game object). It assumes the trigger object is named "Player". 'distance' is near the trigger object needs to be before a message is displayed.
var distance : float = 0.3;
private var goPlayer : GameObject;
function Start() {
goPlayer = GameObject.Find("Player");
}
function OnGUI() {
if ((goPlayer.transform.position - transform.position).magnitude < distance)
GUI.Label(Rect(50,50, 300, 50), "Some Text");
}
It worked well! But i'm a little bit mest up with the "GUI.Label(Rect", so here's how I want my text to look like:
Pixel offset X:0 Y:0
Anchor: middle center
Alignment: left
Line Spacing: 1
Tab Size: 1
Font Size: 30
If you can solve this, just send me back the "GUI.Label(Rect" with the information above.
Thanks by the way!
Oh well then, I'll try to figure it out myself with GUISkins and GUIStyles, although thanks!
~crusherxman