Advertisement
IRCSS

In Game Camera Movement like Scene view

Nov 9th, 2018
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MoveCamera : MonoBehaviour {
  6.  
  7.  
  8.     public float HorizontalVerticalSensitivity = 0.1f;
  9.     public float UpDownSensitivity = 0.015f;
  10.     public bool InvertedY = false;
  11.     public float SpeedMultiplyerOnShiftPressed = 4f;
  12.  
  13.     private float moveUpDown;
  14.     private float speedMultiplyer = 1f;
  15.     private float inversion = -1f;
  16.     void Start()
  17.     {
  18.         if (InvertedY) inversion = 1f;
  19.         else inversion = -1f;
  20.  
  21.     }
  22.    
  23.     void Update () {
  24.  
  25.         if (!Input.GetKey(KeyCode.Mouse1)) return;
  26.        
  27.         float x = Input.GetAxis("Horizontal");
  28.         float y = Input.GetAxis("Vertical");
  29.         float mouseX = Input.GetAxis("Mouse X");
  30.         float mouseY = Input.GetAxis("Mouse Y");
  31.  
  32.         speedMultiplyer = Mathf.Lerp(speedMultiplyer, 1f, 0.1f);
  33.         if (Input.GetKey(KeyCode.LeftShift))
  34.         {
  35.             speedMultiplyer += 0.2f;
  36.             speedMultiplyer = Mathf.Clamp(speedMultiplyer, 1f, SpeedMultiplyerOnShiftPressed);
  37.         }
  38.  
  39.         moveUpDown = Mathf.Lerp(moveUpDown, 0f, 0.1f);
  40.         if (Input.GetKey(KeyCode.E)) moveUpDown += UpDownSensitivity;
  41.         if (Input.GetKey(KeyCode.Q)) moveUpDown -= UpDownSensitivity;
  42.  
  43.         this.transform.Rotate(Vector3.up * mouseX, Space.World);
  44.         this.transform.Rotate(this.transform.right *-1f * mouseY, Space.World);
  45.         this.transform.position += this.transform.right * x* HorizontalVerticalSensitivity * speedMultiplyer;
  46.         this.transform.position += this.transform.forward * y* HorizontalVerticalSensitivity * speedMultiplyer;
  47.         this.transform.position += this.transform.up * moveUpDown* speedMultiplyer;
  48.  
  49.  
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement