Advertisement
Guest User

RTS Camera Controller

a guest
Nov 13th, 2018
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CameraController : MonoBehaviour
  5. {
  6.     public Vector2 Limit;
  7.     public float MinZoom,MaxZoom;
  8.    
  9.     // Update is called once per frame
  10.     void Update ()
  11.     {
  12.         Vector3 pos = transform.position;
  13.  
  14.         float scroll = Input.GetAxis("Mouse ScrollWheel");
  15.         pos.x += Input.GetAxis("Horizontal") * .3f;
  16.         pos.y += -scroll * 5f;
  17.         pos.z += Input.GetAxis("Vertical") * .3f;
  18.  
  19.         pos.y = Mathf.Clamp(pos.y,MinZoom,MaxZoom);
  20.  
  21.         /*Camera.main.fieldOfView -= scroll*20;
  22.         Camera.main.fieldOfView = Mathf.Clamp(Camera.main.fieldOfView,MinZoom,MaxZoom);*/
  23.  
  24.         pos.x = Mathf.Clamp(pos.x,-Limit.x,Limit.x);
  25.         pos.z = Mathf.Clamp(pos.z,-Limit.y,Limit.y);
  26.         transform.position = pos;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement