I’m trying to make a GUI Horizontal Slider. An error occurs where Unity thinks the min and max slider values (0.0, 20.0) are doubles and not floats. How do I fix this error?
C# doesn’t “think” those are doubles, they are doubles
In C# the default real-literal type is double. In UnityScript it’s float.
You just need to add an “f” at the end to make it a float literal. On the other hand if you need a double in UnityScript add a “d”:
//C#
float a = 5.0f;
float b = 5f;
double c = 5.0d;
double d = 5d;
double e = 5.0;
//UnityScript
var f = 5.0; // will be a float
var g = 5.0d; // will be a double
Its an artefact of the fact that doubles are better in almost all cases, so they are the C# default. 3D Game development is one of the rare cases where floats are better.
Its an artefact of the fact that doubles are better in almost every application, so they are the C# default. Game development is one of the few cases where floats are better.