- Home /
 
How can I set limits to camera pan on X and Y axis
So I got the camera to pan already, but when I try to add some boundaries with Mathf.Clamp I get come issues. Here is my panning code...
 using UnityEngine;
 using System.Collections;
 
 public class CameraDrag : MonoBehaviour 
 {
     public float dragSpeed = 2.0f;
     private Vector3 dragOrigin;
     private bool isPanning;
 
 
     // Use this for initialization
     void Start () 
     {
         
     }
     
     // Update is called once per frame
     void Update () 
     {
         if (Input.GetMouseButtonDown(0)) 
         {
             dragOrigin = Input.mousePosition;
             isPanning = true;
         }
 
         if (!Input.GetMouseButton(0)) 
         {
             isPanning = false;
         }
 
         if (isPanning) 
         {
             Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin);
 
             Vector3 move = new Vector3(pos.x * dragSpeed, pos.y * dragSpeed, 0);
             transform.Translate(move, Space.Self);
 
             transform.position = new Vector3(Mathf.Clamp(Transform.position.x, -10,10),Mathf.Clamp(transform.position.y, -10,10),0);  //without this the code works fine but I want to set boundaries for the actual map.
         }
     }
 }
 
               So the last line of code is the problem, without it the code works fine but I need to set the boundaries somehow. Any help would be really appreciate it.
Victor
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by YourGamesBeOver · Mar 07, 2014 at 12:40 AM
In your problem line, you capitalized transform ("Transform.position.x"). this refers to the class itself and not the instance.
Well, that fixed it... it was a very dumb mistake from me. Thank you very much @YourGamesBeOver.
Your answer