- Home /
Question by
KilometersWinters · Jul 07, 2017 at 02:48 PM ·
positiontransform.translate
How do I test for the Y Coordinate?
So I am trying to test if my player is at a certain y coordinate (2 in my case), and I don't know how to do it. Oh and I'm doing it in C#
Comment
I usually just do something like this
if (Vector3.Distance(transform.position, targetPos) < 0.01f)
{
//Code here
}
Answer by FlaSh-G · Jul 07, 2017 at 03:16 PM
Mathf.Approximately(transform.position.y, 2)
Mathf.Approximately is nice to use because sometimes, float values are almost alike, but not exactly.
Just to expand on this, in case you need to know, it would be
if ($$anonymous$$athf.Apporximately(object.transform.position.y, 2))
{
//code
}
This Code wouldn't even compile. $$anonymous$$athf.Approximately returns a bool specifying whether or not the floats are similar.
I'm sorry, I really should have looked it up first. I changed it now.