C# code is making 0.0 a double and not a float

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?

walkSpeed = GUI.HorizontalSlider(new Rect(150, 40, 100, 20), walkSpeed, 0.0, 20.0);

C# doesn’t “think” those are doubles, they are doubles :slight_smile:

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

UA ate my answer, again :frowning:

0.0f, 20f

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.

0.0f, 20.0f

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.