Недавно начал изучать Unity3D, по книге "Unity3D в действии" Джозефа Хокинга. Есть код, который отвечает за вращение капсулы, хотел бы более подробного его объяснения, т.к. в книге не очень понятно.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour {
public enum RotationAxes
{
MouseXAndY = 0,
MouseX = 1,
MouseY = 2
}
public float sensitivyHor = 4.0f;
public float sensitivyVert = 4.0f;
public float minimumVert = -0.90f;
public float maximumVert = 0.90f;
private float _rotationX = 0;
public RotationAxes axes = RotationAxes.MouseXAndY;
void Update () {
if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivyHor,0);
}
else if (axes == RotationAxes.MouseY)
{
_rotationX -= Input.GetAxis("Mouse Y") * sensitivyVert;
_rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert);
float _rotationY = transform.localEulerAngles.y;
transform.localEulerAngles = new Vector3(_rotationX, _rotationY, 0);
}
else
{
_rotationX -= Input.GetAxis("Mouse Y") * sensitivyHor;
_rotationX = Mathf.Clamp(_rotationX,minimumVert,maximumVert);
float delta = Input.GetAxis("Mouse X") * sensitivyHor;
float _rotationY = transform.localEulerAngles.y + delta;
transform.localEulerAngles = new Vector3(_rotationX,_rotationY,0);
}
}
}