Advertisement
kasru

RTS locked/unlocked camera

Feb 5th, 2013
1,873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //****** Donations are greatly appreciated.  ******
  2. //****** You can donate directly to Jesse through paypal at  https://www.paypal.me/JEtzler   ******
  3.  
  4. var CamSpeed = 1.00;
  5. var GUIsize = 25;
  6. var target : Transform;
  7. var cameraLocked : boolean = false;
  8.  
  9. function OnGUI () {
  10.  
  11.     if (GUI.Button (Rect (Screen.width / 2,Screen.height / 2,120,20), "Lock Camera")) {
  12.         cameraLocked = !cameraLocked;
  13.     }
  14. }
  15.  
  16. function Update () {
  17.  
  18.     if(Input.GetKeyDown("left shift")) {
  19.  
  20.         transform.position.x = target.transform.position.x;
  21.         transform.position.z = target.transform.position.z -50;
  22.     }
  23.  
  24.     if(cameraLocked == false) {
  25.         var recdown = Rect (0, 0, Screen.width, GUIsize);
  26.         var recup = Rect (0, Screen.height-GUIsize, Screen.width, GUIsize);
  27.         var recleft = Rect (0, 0, GUIsize, Screen.height);
  28.         var recright = Rect (Screen.width-GUIsize, 0, GUIsize, Screen.height);
  29.  
  30.         if (recdown.Contains(Input.mousePosition))
  31.             transform.Translate(0, 0, -CamSpeed, Space.World);
  32.        
  33.     if (recup.Contains(Input.mousePosition))
  34.             transform.Translate(0, 0, CamSpeed, Space.World);
  35.        
  36.     if (recleft.Contains(Input.mousePosition))
  37.             transform.Translate(-CamSpeed, 0, 0, Space.World);
  38.        
  39.     if (recright.Contains(Input.mousePosition))
  40.             transform.Translate(CamSpeed, 0, 0, Space.World);
  41.      }
  42.  
  43.  
  44.     else if(cameraLocked == true){
  45.         transform.position.x = target.transform.position.x;
  46.         transform.position.z = target.transform.position.z -50;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement