Question by
royspandan1 · Jul 06, 2020 at 06:24 PM ·
android build
I am getting different behavior on the project and its Android build.
I have this code snippet which causes the enemies to reflect back the walls when they reach their position obeying the Snell's law. The code works fine when I run it on my editor. But when i build the game on Android, the x and y both get flipped when hitting the left and right wall.
Here is the attached code. The wall GameObjects are attached to the canvas which is on camera space and scales with srceen size.
GameObject[] walls;
private void Start()
{
walls = GameObject.FindGameObjectsWithTag("Wall");
}
private void OnBecomeInvisible()
{
HitWall();
}
private void HitWall()
{
Vector2 vel;
if (transform.position.x < walls[0].transform.position.x || transform.position.x > walls[1].transform.position.x)
{
vel = rb.velocity;
vel.x *= -1;
rb.velocity = vel;
}
if (transform.position.y < walls[2].transform.position.y || transform.position.y > walls[3].transform.position.y)
{
vel = rb.velocity;
vel.y *= -1;
rb.velocity = vel;
}
}
Comment
Even if I move the function to Fixed Update, both x and y are getting flipped on all walls in android, but on the editor its perfectly fine. Why is it behaving as such on android?