- Home /
The question is answered, right answer was accepted
How to check the position of an object
Hi all,
I am trying to test if an object has fallen below a certain point on the Y vector and if so then I will run another function.
I'm just not sure how I can do an 'if' function to access the Y value in Vector3.
I was thinking it would look something like this:
if (Vector3(x,y<1.5,0)
{
anotherfunction()
}
I'm pretty certain that this won't work and that there is more to it, but I was hoping someone could point me in the right direction.
Thank
Looks like you need a refresh in how does "if statements" works http://unity3d.com/learn/tutorials/modules/beginner/scripting/if-statements
Ok i've looked into it a bit further I think that the below should work
if (transform.position.y < 1.5)
{
anotherfunction();
}
else
{
//do nothing
}
if I put this in the object's script then this should work right? or at least it seems right to me.
Basically when the object falls below the y value of 1.5 I what the other function to run.
I think it was simpler than I was trying to make it. I'll try it out when I get home.
Sorry for being a noob.
yes, you are right. Just as a note, when using floats use the :1.5f notation like this :
if (transform.position.y < 1.5f)
or else you risk that your values are casted to int
values being cast to int isn't a problem, this is safe:
float x = 15;
What is a problem is that when you write "1.5", that's a double, not a float, and your stuff won't compile.
Anyways, the question is resolved, closing.