Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CameraController : MonoBehaviour {
- public float panSpeed=30f;
- public float panBorderThickness = 10f;
- public float scrollSpeed = 5f;
- public float minY = 10f;
- public float maxY = 80f;
- // Use this for initialization
- void Update(){
- if (Input.GetKey("w") || Input.mousePosition.y >= Screen.height - panBorderThickness){
- transform.Translate(Vector3.forward*panSpeed* Time.deltaTime, Space.Self);
- }
- if (Input.GetKey("w") && Input.GetKey("left shift")){
- transform.Translate(Vector3.forward*panSpeed*5* Time.deltaTime, Space.Self);
- }
- if (Input.GetKey("s") || Input.mousePosition.y <= panBorderThickness){
- transform.Translate(Vector3.back*panSpeed* Time.deltaTime, Space.Self);
- }
- if (Input.GetKey("s") && Input.GetKey("left shift")){
- transform.Translate(Vector3.back*panSpeed*5* Time.deltaTime, Space.Self);
- }
- if (Input.GetKey("d") || Input.mousePosition.x >= Screen.width - panBorderThickness){
- transform.Translate(Vector3.right*panSpeed* Time.deltaTime, Space.Self);
- }
- if (Input.GetKey("d") && Input.GetKey("left shift")){
- transform.Translate(Vector3.right*panSpeed*5* Time.deltaTime, Space.Self);
- }
- if (Input.GetKey("a") || Input.mousePosition.x <= panBorderThickness){
- transform.Translate(Vector3.left*panSpeed* Time.deltaTime, Space.Self);
- }
- if (Input.GetKey("a") && Input.GetKey("left shift")){
- transform.Translate(Vector3.left*panSpeed*5* Time.deltaTime, Space.Self);
- }
- if (Input.GetKey("e")){
- transform.Rotate(Vector3.up*panSpeed*3 * Time.deltaTime, Space.World);
- }
- if (Input.GetKey("q")){
- transform.Rotate(Vector3.down*panSpeed*3 * Time.deltaTime, Space.World);
- }
- float scroll = Input.GetAxis("Mouse ScrollWheel");
- Vector3 pos = transform.position;
- pos.y -= scroll * 1000 * scrollSpeed*Time.deltaTime;
- pos.y = Mathf.Clamp(pos.y,minY,maxY);
- transform.position = pos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement