x


How to make floats in the textfield?

Hi, in my textfield I do something like this:

var px1 = 0.0;
var rtextx = "";
function OnGUI(){
px1 = select.localPosition.x;//Select: a simple transform
ptextx = px1.ToString();
ptextx = GUI.TextField(Rect (70, 40, 30, 20),ptextx, 25);
select.localPosition.x = px1 = int.Parse(ptextx);
}

But the problem is that it does not acept the period(.), but I dont know maybe the reason is different, but the thing is that when I write like 0.5 it doesnt change of position.

Another thing can be to use a floatField() but I dont know a lot of that so if some one knows about the floatField() please write a script about of how to do it. Please answer I will really apreciate it. :)

more ▼

asked Nov 19 '10 at 12:28 AM

Uriel_96 gravatar image

Uriel_96
945 61 70 81

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

If you want a float, you can't use int.Parse, because that just gives you an int. So you need float.Parse.

FloatField is for the editor GUI only.

more ▼

answered Nov 19 '10 at 12:37 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

oh thanks, I dont even note that one

Nov 19 '10 at 12:41 AM Uriel_96
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5096
x3697
x888
x182
x151

asked: Nov 19 '10 at 12:28 AM

Seen: 1430 times

Last Updated: Nov 19 '10 at 12:28 AM