Advertisement
Muk99

FlyThrough

Feb 2nd, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(Camera))]
  4. public class FlyThrough : MonoBehaviour {
  5.  
  6.     public Vector2 moveSensibility = Vector2.one * 15f;
  7.     public Vector2 mouseSensibility = Vector2.one * 2f;
  8.     public float shiftMultiplier = 3f;
  9.  
  10.     private float vertical { get { return Input.GetAxis("Vertical") * moveSensibility.y; } }
  11.     private float horizontal { get { return Input.GetAxis("Horizontal") * moveSensibility.x; } }
  12.     private float mouseX { get { return Input.GetAxis("Mouse X") * mouseSensibility.x; } }
  13.     private float mouseY { get { return Input.GetAxis("Mouse Y") * mouseSensibility.y; } }
  14.  
  15.     private void Update() {
  16.         var movement = transform.forward * vertical * Time.deltaTime + transform.right * horizontal * Time.deltaTime;
  17.  
  18.         if(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
  19.             movement *= shiftMultiplier;
  20.  
  21.         transform.position += movement;
  22.  
  23.         transform.Rotate(Vector3.up, mouseX, Space.World);
  24.         transform.Rotate(transform.right, -mouseY, Space.World);
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement