Advertisement
thegreen9

UNITY Camera Controller

Mar 28th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraController : MonoBehaviour {
  6.     public float panSpeed=30f;
  7.     public float panBorderThickness = 10f;
  8.     public float scrollSpeed = 5f;
  9.     public float minY = 10f;
  10.     public float maxY = 80f;
  11.  
  12.  
  13.     // Use this for initialization
  14. void Update(){
  15.  
  16.  if (Input.GetKey("w") || Input.mousePosition.y >= Screen.height - panBorderThickness){
  17.      transform.Translate(Vector3.forward*panSpeed* Time.deltaTime, Space.Self);
  18. }
  19. if (Input.GetKey("w") && Input.GetKey("left shift")){
  20.      transform.Translate(Vector3.forward*panSpeed*5* Time.deltaTime, Space.Self);
  21. }
  22.  if (Input.GetKey("s") || Input.mousePosition.y <= panBorderThickness){
  23.      transform.Translate(Vector3.back*panSpeed* Time.deltaTime, Space.Self);
  24. }
  25. if (Input.GetKey("s") && Input.GetKey("left shift")){
  26.      transform.Translate(Vector3.back*panSpeed*5* Time.deltaTime, Space.Self);
  27. }
  28.  if (Input.GetKey("d") || Input.mousePosition.x >= Screen.width - panBorderThickness){
  29.      transform.Translate(Vector3.right*panSpeed* Time.deltaTime, Space.Self);
  30. }
  31. if (Input.GetKey("d") && Input.GetKey("left shift")){
  32.      transform.Translate(Vector3.right*panSpeed*5* Time.deltaTime, Space.Self);
  33. }
  34.  if (Input.GetKey("a") || Input.mousePosition.x <= panBorderThickness){
  35.      transform.Translate(Vector3.left*panSpeed* Time.deltaTime, Space.Self);
  36. }
  37. if (Input.GetKey("a") && Input.GetKey("left shift")){
  38.      transform.Translate(Vector3.left*panSpeed*5* Time.deltaTime, Space.Self);
  39. }
  40.  if (Input.GetKey("e")){
  41.      transform.Rotate(Vector3.up*panSpeed*3 * Time.deltaTime, Space.World);
  42.  }
  43.  if (Input.GetKey("q")){
  44.      transform.Rotate(Vector3.down*panSpeed*3 * Time.deltaTime, Space.World);
  45.  }
  46. float scroll = Input.GetAxis("Mouse ScrollWheel");
  47. Vector3 pos = transform.position;
  48. pos.y -= scroll * 1000 * scrollSpeed*Time.deltaTime;
  49. pos.y = Mathf.Clamp(pos.y,minY,maxY);
  50. transform.position = pos;
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement