Search Unity

Adapt distance to all screen sizes

Discussion in '2D' started by Silasi, Jul 14, 2019.

  1. Silasi

    Silasi

    Joined:
    Jul 25, 2016
    Posts:
    48
    Hello there,

    I run a script which lerps an object from left: Vector2(-7, 0) to right: Vector2(7, 0). However, the line that does this is working only on my screen and it does not adapt to other screen sizes, it just lerps between those exact positions which causes the object to leave the screen boundaries.

    How can I adapt the distance to all screen sizes?

    Code (CSharp):
    1. transform.position = Vector2.Lerp(left.position, right.position, (Mathf.PingPong(Time.time * speed, 1))