Search Unity

Limit camera movement (please help)

Discussion in 'Scripting' started by technotdc, Oct 1, 2014.

  1. technotdc

    technotdc

    Joined:
    Oct 21, 2011
    Posts:
    60
    Hi....

    I will use this script to move Up/down camera....

    Code (csharp):
    1.  
    2. public var minMaxZoomHeight : Vector2;
    3. private var scrolled : int = 0;
    4. var Orthographic : boolean = false;
    5. var scrollspeed : int = 150;
    6.  
    7. function Update () {
    8.    
    9.    var mouseWheel : float = Input.GetAxis ("Zoom");
    10.  
    11.      if(mouseWheel != 0){
    12.        if(mouseWheel > 0 && scrolled < minMaxZoomHeight.y){
    13.          scrolled = mouseWheel + scrolled;
    14.          transform.Translate(Vector3.up* Time.deltaTime * mouseWheel * scrollspeed);
    15.        }
    16.        else if(mouseWheel < 0 && scrolled > minMaxZoomHeight.x){
    17.          scrolled = mouseWheel + scrolled;
    18.          transform.Translate(Vector3.up * Time.deltaTime * mouseWheel * scrollspeed);
    19.        }
    20.      }
    21.    }
    22.  
    how can put limits for the movement up/down ,please ?
     
  2. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    669
    Just don't apply the transform.Translate() if the height (transform.position.y) is greater than any given limit. Same for going down.