- Home /
Check if player position is greater than one value and less than another?
I'm making this C# script
public int getOn;
public int getOff;
public GameObject player;
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
}
void OnTriggerEnter ()
{
if(player.transform.position.y....
}
That's all I have. Can someone show me how to format to code to say that if player's poisition on Y axis if greater than getOn and less than getOff, then perform such and such actions. I'm sure it's pretty simple, I just can't think of how to do it.
Comment
Best Answer
Answer by AyAMrau · Jun 27, 2014 at 12:40 AM
if(player.transform.position.y > getOn && player.transform.position.y < getOff)
{ ... }
If this is new to you I recommend some reading on logical operators.
Also this will be executed if any object (not limited to player) triggered the collision. If you want to limit it you should check whether the collider that triggered the collision has the Player tag.