Exemplo n.º 1
0
 private float Move(float position, float target, float trackSpeed)
 {
     if (position == target)
     {
         return(position);
     }
     else
     {
         Bounds cameraBounds                       = CameraViewPort.OrthographicBounds();
         float  distanceToLeftBorder               = Mathf.Sqrt((cameraBounds.center.x - cameraBounds.min.x) * (cameraBounds.center.x - cameraBounds.min.x));
         float  distanceToRightBorder              = Mathf.Sqrt((cameraBounds.center.x - cameraBounds.max.x) * (cameraBounds.center.x - cameraBounds.max.x));
         float  direction                          = Mathf.Sign(target - position);
         float  nextPosition                       = position + trackSpeed * Time.deltaTime * direction;
         float  nextPositionAndLeftBorderDistance  = Mathf.Sqrt((nextPosition - LeftBorder.transform.position.x) * (nextPosition - LeftBorder.transform.position.x));
         float  nextPositionAndRightBorderDistance = Mathf.Sqrt((nextPosition - RightBorder.transform.position.x) * (nextPosition - RightBorder.transform.position.x));
         if (nextPositionAndLeftBorderDistance <= distanceToLeftBorder || nextPositionAndRightBorderDistance <= distanceToRightBorder)
         {
             return(position);
         }
         else
         {
             position = nextPosition;
             return((direction == Mathf.Sign(target - position)) ? position: target);
         }
     }
 }
Exemplo n.º 2
0
    void Update()
    {
        Move();
        Bounds cameraBounds = CameraViewPort.OrthographicBounds();

        if (transform.position.x > cameraBounds.max.x || transform.position.x < cameraBounds.min.x)
        {
            Destroy(this.gameObject);
        }
    }
Exemplo n.º 3
0
    private bool IsInCamera()
    {
        Bounds cameraBounds = CameraViewPort.OrthographicBounds();

        return(Camera.main != null ? (transform.position.x < cameraBounds.max.x && transform.position.x > cameraBounds.min.x) : false);
    }