Example #1
0
    Vector2 CalculatePosition()
    {
        var pos         = UnitConversion.PointToScreenRatio(transform.position);
        var perspective = RoadCommon.PERSPECTIVE(pos.y, RoadSize.Get().y);
        var max         = RoadSize.Get().x *perspective;

        var offset = Random.Range(-max, max);

        return(new Vector2(transform.position.x + offset, transform.position.y));
    }
Example #2
0
 public void Update()
 {
     if (!IsOnScreen())
     {
         Destroy(gameObject);
     }
     else
     {
         offset         += CalculateOffset();
         currentPosition = new Vector2(startPosition.x, startPosition.y + offset);
         perspective     = RoadCommon.PERSPECTIVE(currentPosition.y, RoadSize.Get().y);
         float distanceFromCenter = 0.5f - startPosition.x;
         currentPosition.x += RoadCommon.CURVE(Curvature.Get(), perspective) + distanceFromCenter * perspective;
         ApplyPosition(currentPosition);
     }
 }
Example #3
0
 private void Awake()
 {
     RoadSize.Set(size);
 }