The question is answered, right answer was accepted
Incorrect Vector2 values when using the *new* keyword?
Hello, I am using Vector2 structures to track the location of a game piece as it moves between two points in space on a 2D plane.
I seem to be getting very strange values according to the debugger when I initialize my local Vectors. I am pulling two INT values and casting them into local float variables. You can see the values of the respective floats used to initialize the Vector2 named startPosition below in the Watch tab.
Additionally, I tried using the game piece's transform values to set a 'current' position of the game piece. That seems to produce a Vector2 with what I presume are initial values:
I am really confused by this. In the second example, am I getting this result because I'm leveraging a member structure (transform.position) for a local variable's initialization?
I'm using Unity 5.9.6 on Mac OS X Sierra (ver. 10.12.4) The class that has this code in it is using the following libraries: using System.Collections; using System.Collections.Generic; using UnityEngine;
Any input would be greatly appreciated!
Thank you in advance, Matthew
Well it turns out this is probably an issue with the debugger - using Debug.Log() to write the coordinate values to the console, I can see that they appear correct. So I'll close this question as nothing is actually wrong with Vector2 instantiation.
Answer by pdx_matthew · Apr 25, 2017 at 02:06 AM
PS - the build log is clean, no errors, warnings or info messages.
I am bumping myself. :(
Tried rebooting, no effect. Values assigned to the Vector2 structure appear random each time I run through the code. Perhaps I need to downgrade Unity to a more stable version? Or uninstall and reinstall?
Follow this Question
Related Questions
Predict the hit position 0 Answers
Spawn Objects on Grid - how to define size? 1 Answer
Why does float division not work? 3 Answers
How do I find a point along a line with a forced x and z values 0 Answers