Wutangers 09 сен 2023, 13:00
Вот сам скрипт из учебника.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mouselook : MonoBehaviour
{
public enum RotationAxes {
MouseXandY = 0,
MouseX = 1,
MouseY = 2
}
public RotationAxes axes = RotationAxes.MouseXandY;
public float sensitivityHor = 9.0f;
public float sensitivityVert = 9.0f;
public float minimumVert = -45.0f;
public float maximumVert = 45.0f;
private float verticalRot = 0;
// Start is called before the first frame update
void Start() {
Rigidbody body = GetComponent<Rigidbody>();
if (body != null) {
body.freezeRotation = true;
}
}
// Update is called once per frame
void Update()
{
if (axes == RotationAxes.MouseX) {
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityHor, 0);
}
else if (axes == RotationAxes.MouseY) {
verticalRot -= Input.GetAxis("Mouse Y") * sensitivityVert;
verticalRot = Mathf.Clamp(verticalRot, minimumVert, maximumVert);
float horizontalRot = transform.localEulerAngles.y;
transform.localEulerAngles = new Vector3(verticalRot, horizontalRot, 0);
}
else {
verticalRot -= Input.GetAxis("Mouse Y") * sensitivityVert;
verticalRot = Mathf.Clamp(verticalRot, minimumVert, maximumVert);
float delta = Input.GetAxis("Mouse X") * sensitivityHor;
float horizontalRot= transform.localEulerAngles.y + delta;
transform.localEulerAngles = new Vector3(verticalRot, horizontalRot, 0);
}
}
}