- Home /
The question is answered, right answer was accepted
Debug states its true but if doesnt trigger.
Debug.Log(this.transform.localEulerAngles+" | "+weaponButtons.camEuler);
if(this.transform.localEulerAngles == weaponButtons.camEuler){
Debug.Log("Check");
var weaponV4 : Vector4 = profileScript.ModWeapon(selectedWeaponType, "Return", 0);
Debug.Log(weaponV4);
weaponButtons.damageText.text = "Damage "+weaponV4.x;
weaponButtons.rangeText.text = "Range "+weaponV4.y;
weaponButtons.clipSizeText.text = "Clip Size "+weaponV4.z;
weaponButtons.reloadRateText.text = "Reload Rate "+weaponV4.w;
}
this is running in the Update on a camera
The Debug shows that my local euler is 0, 180, 0 and that the weaponButtons.camEuler is 0, 180, 0.
the if statement is not running... the "Check" debug is not running...
How can i fix this?
Answer by tanoshimi · Nov 15, 2013 at 10:49 AM
transform.localEulerAngles
(and, I assume, your weaponButtons.camEuler variable) are vectors of floating point variables, and it's never a good idea to check for equality of floating point numbers.
Instead, check whether the difference between the components is less than a certain acceptable margin of error, or perhaps compare the dot product of the two vectors to see whether it's sufficiently close to 1.
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Cube terrain with perlin noise 1 Answer
UnityEngine has no appropriate version problem 1 Answer
Singletons in music script? 2 Answers
2.5D ledge hang with javascript 0 Answers