- Home /
Checking GameObject Position on Andriod
so i'm trying to rotate this gameobject but don't rotate it too much as my gameobject should stop rotating when it reaches postion.x 2.5 when i move it does work on unity editor but not
if(tiltY < 0 && playerTrasform.position.x >= 2.5f)
{
playerTrasform.transform.Rotate(0.0f, 0.0f, 0.30f);
}
if (tiltY > 0 && playerTrasform.position.x <= -2.5f)
{
playerTrasform.transform.Rotate(0.0f, 0.0f, -0.30f);
}
Comment
Answer by sachinbirajdar · Dec 25, 2020 at 06:46 AM
If you want to stop gameobject rotation when it reaches at 2.5x and -2.5x then try this.With this code gameobject will rotate within -2.5x and 2.5x.
if(tiltY < 0 && playerTrasform.position.x <= 2.5f) // if gameobject //position is less than 2.5x
{
playerTrasform.transform.Rotate(0.0f, 0.0f, 0.30f);
}
if (tiltY > 0 && playerTrasform.position.x >= -2.5f)// if gameobject
//position is greater than 2.5x
{
playerTrasform.transform.Rotate(0.0f, 0.0f, -0.30f);
}