Hi everybody. In my game a have a 2D block which moves forward and backward horizontally. When the 2D block reach the edge of the screen it change it direction and move to the other side and vice versa.
if (transform.position.x >= 27.3)
{
speed = speed * -1;
}
if (transform.position.x; <= -6.99)
{
speed = speed * -1;
} GetComponent<Rigidbody2D> ().velocity = new Vector2 (speed, GetComponent<Rigidbody2D> ().velocity.y);
Now the problem is that not all mobiles have the same screen size so in some cases the block might go outside of the screen then change it direction and in other cases the block might change it direction before it reach the edge of the screen. So what can i do to solve this problem
Thanks