- Home /
How does GUI TextField Work?
I wanted to make 5 different text fields for 5 different axis of an object: X, Y, Z, Pitch, and Yaw (no Roll). I figured that the player would type in coordinates for the X, Y, and Z and then type in the rotation (in degrees) for the Pitch and Yaw, then hit Enter and the object would gradually move to those coordinates and rotation. Although I'm not so sure I understand how GUI.TextField works, at least in terms of position on the screen. Could someone please be condescending enough to help me out with this?
(Please Excuse My Noobishness In Scripting)
Answer by tanoshimi · Dec 01, 2013 at 08:36 AM
All GUI.xxx functions use coordinates defined in screen space, which are measured in pixels starting with (0,0) at the top-left corner. So, this line creates a textfield that is 200 pixels wide, 20 pixels high, with its top-left corner 10 pixels in and 10 pixels down from the top left corner of the screen. Its initial value is equal to the value of the variable stringToEdit, and every time it is changed it updates that variable:
stringToEdit = GUI.TextField(new Rect(10, 10, 200, 20), stringToEdit);
That's great; I got the text field to work. Only problem is, how do I turn a string into a value of Vector3? I tried this: xAxis = transform.position += Vector3(0,0,xAxis) * Time.deltaTime;
But I got a compiler error. Anything I'm doing wrong?
// uJS
var floatFromString : float = parseFloat( stringToEdit );
Your answer
Follow this Question
Related Questions
Semi Dynamic Shadows 1 Answer
Transform.Position stop? 1 Answer
Following Mouse Motion 1 Answer
Move object with mouse without passing through colliders 0 Answers
C# trying to move a object 2 Answers