-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraController.cs
More file actions
52 lines (35 loc) · 1.4 KB
/
Copy pathCameraController.cs
File metadata and controls
52 lines (35 loc) · 1.4 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
// VARIABLES
[SerializeField] GameObject player;
[SerializeField] private float mouseSensitivity_X;
[SerializeField] private float mouseSensitivity_Y;
[SerializeField] float rotation = 0f;
public float vistaSu = -15f;
public float vistaGiu = 30f;
void Start()
{
//nascondo e blocco il puntatore mentre gioco
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
rotation += Input.GetAxis("Mouse X") * mouseSensitivity_X * Time.deltaTime;
player.transform.eulerAngles = new Vector3(0, rotation, 0);
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity_Y * Time.deltaTime;
//transform.Rotate(Vector3.right, -mouseY);
// Get the current rotation angles.
Vector3 eulerAngles = transform.localEulerAngles;
// Returned angles are in the range 0...360. Map that back to -180...180 for convenience.
if (eulerAngles.x > 180f)
eulerAngles.x -= 360f;
// Increment the pitch angle, respecting the clamped range.
eulerAngles.x = Mathf.Clamp(eulerAngles.x - mouseY, vistaSu, vistaGiu);
// Orient to match the new angles.
transform.localEulerAngles = eulerAngles;
}
}