void Update()
{
transform.Translate(0f, movSpeed * Time.deltaTime, 0f);
if (Input.GetMouseButtonDown(0))
{
Debug.Log("click");
}
if (transform.localRotation.eulerAngles.z == -45)
Debug.Log("rotated");
}
in the inspector my rotation on z is set to -45, nothing logs in the console, tried making a GameObject variable, didn’t work, tried putting this.transform, didn’t work, doesn’t matter if it’s -45 or -45f, it just doesn’t work
What exactly are you attempting here??
The above expression will almost guaranteed NEVER be true. Here’s why:
Floating (float) point imprecision:
Never test floating point (float) quantities for equality / inequality. Here’s why:
https://starmanta.gitbooks.io/unitytipsredux/content/floating-point.html
Now that you have had your coffee, don’t forget about floating point imprecision:
// @kurtdekker: don't forget about floating point imprecision
using UnityEngine;
public class FloatingPointImprecision : MonoBehaviour
{
void Start ()
{
float a = 2000.0f;
float b = 0.1f;
float product = (a * b);
float answer = 200;
Debug.Log( "a = " + a);
Debug.Log( "b = " + b);
Debug.Log( "product of a*b = " + product);
Debug.Log( "answer =…
This will explain it all.
In an IEEE single-floating point number you can represent certain numbers perfectly and unambiguously.
For instance, 0.5f is precisely represented as 0x3f000000
However, 0.1f CANNOT be precisely represented. One possible approximate representation is 0x3DCCCCCD
The analogy is that you cannot show 1/3rd precisely as a decimal.
0.33 is correct to 2 decimal places
0.3333 is correct to 4 places
etc.
But you can never exactly represent 1/3rd as a decimal numeral. Yo…
“Think of [floating point] as JPEG of numbers.” - orionsyndrome on the Unity3D Forums
Furthermore, reading Euler angles back from a transform is almost ALWAYS a disaster, or at least a complexity you don’t want. More reading:
All about Euler angles and rotations, by StarManta:
https://starmanta.gitbooks.io/unitytipsredux/content/second-question.html