Created
January 8, 2022 14:31
-
-
Save MarcelvanDuijnDev/539811f86e16ac6a684d09bc41967c7e to your computer and use it in GitHub Desktop.
Unity Camera Movement - FreeCam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Movement_FreeCamera : MonoBehaviour | |
{ | |
[SerializeField] private float _Speed = 5; | |
[SerializeField] private float _SprintSpeed = 8; | |
private float _CurrentSpeed; | |
void Start() | |
{ | |
Cursor.visible = false; | |
Cursor.lockState = CursorLockMode.Locked; | |
} | |
void Update() | |
{ | |
if (Input.GetKey(KeyCode.LeftShift)) | |
_CurrentSpeed = _SprintSpeed; | |
else | |
_CurrentSpeed = _Speed; | |
float xas = Input.GetAxis("Horizontal"); | |
float zas = Input.GetAxis("Vertical"); | |
transform.Translate(new Vector3(xas,0, zas) * _CurrentSpeed * Time.deltaTime); | |
float mousex = Input.GetAxis("Mouse X"); | |
float mousey = Input.GetAxis("Mouse Y"); | |
transform.eulerAngles += new Vector3(-mousey, mousex, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment