-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMovement_FreeCamera.cs
More file actions
34 lines (27 loc) · 899 Bytes
/
Movement_FreeCamera.cs
File metadata and controls
34 lines (27 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
}
}