Is there a Unity JavaScript equivalent of the .ToFloat function?
No, but you can use System.Convert.ToSingle() from .net. (Or ToDouble, though standard floats are single-precision, but you can use double-precision if you want.)
–Eric
Thanks Eric. What I’m trying to do is to create a GUI slider that “clicks” at every tenth of a unit. So I’m using an Int for the slider’s units, then I want to convert the Int to a float and multiply that by 0.10. Make sense? Unless there’s a better / easier way to do this?
Doesn’t implicit conversion work?
var myInt :int = 10;
var myFloat :float = myInt;
return myFloat * 0.10;
Also, I just tried and multiplying an int with a float will return a float. So the above is equal to:
var myInt :int = 10;
return myInt * 0.10;
Thanks Adrian, yes that works fine!
I prefer to go the other way (so to speak). That way the slider value is the value you actually want to use else where.
public float slider = 0f;
public float interval = 0.1f;
public float sliderMax = 2f;
public void OnGUI() {
slider = GUILayout.HorizontalSlider(Mathf.Round(slider/interval) * interval, 0f, sliderMax);
}
/unsolicited advice