C# float is 0 in debug
Hi,
I have a small problem with a float value.
The value is 0, but I expect 7.32.
Probably a stupid mistake, but I didn't find an answer.
public class GameFieldBuilder : MonoBehaviour {
public float tileSizeX = 7.32f;
void Start () {
Debug.Log("A: " + 7.32f);
Debug.Log("B: " + tileSizeX);
Debug.Log("C: " + tileSizeX.ToString("0.0"));
Output:
A: 7.32
B: 0
C: 0.0
Thanks and best regards
You may wish to check in the editor that you have not set the value of the field to zero accidentally in the inspector on the game object, it would override your default value here.
Answer by PersianKiller · Sep 16, 2017 at 05:29 PM
your code is fine you probably set the value of tileSizeX via unity editor ,in inspector to 0.take a look at it.
or change it to
private float tileSizeX = 7.32f;
and your problem should solve.
Answer by Codorr · Sep 16, 2017 at 05:57 PM
Yes this was the problem, thanks :) Didn't know that it ignores the init value then.
Your answer
Follow this Question
Related Questions
error CS1525: Unexpected symbol `float' 1 Answer
Rotate a Vector2 around the Z axis on a mathematical level 1 Answer
Help with arrays and checking other object's floats 0 Answers
Why is my logic happening 9 times? 0 Answers
Unity VR WebSocket Connection to ThingsBoard Error 'Failed to parse websocket command!' 1 Answer