- Home /
Question by
Ki4Chan · Aug 05, 2017 at 12:00 PM ·
build-error
Object aligns to edge of the screen in editor/ remote 5 but a little off the edge after building APK.
In my project, I have written code to stop the player going from off the screen but it should align to the edge of the screen. It is working fine in the editor and remote, tried in all the screen resolution, but when I build it the player is a little off the edge in two levels out of three. In 3rd it is working fine in Build APK too.
float screenHalfWidthInWorldUnits;
float halfPlayerWidth;
void Start()
{
halfPlayerWidth = transform.localScale.x / 12;
screenHalfWidthInWorldUnits = Camera.main.aspect*Camera.main.orthographicSize;
}
void Update()
{
if (transform.position.x < -screenHalfWidthInWorldUnits + halfPlayerWidth)
{
transform.position = new Vector2(-screenHalfWidthInWorldUnits + halfPlayerWidth, transform.position.y);
}
if (transform.position.x > screenHalfWidthInWorldUnits - halfPlayerWidth) {
transform.position = new Vector2(screenHalfWidthInWorldUnits - halfPlayerWidth, transform.position.y);
}
}
Comment
Your answer