unity clamp rotation using quaternion code example
Example 1: unity clamp rotation
float rotationX = 0;
float rotationY = 0;
void Update() {
rotationX += Input.GetAxis("Vertical") * Time.deltaTime;
rotationX = Mathf.Clamp(rotationX, minRotationX, maxRotationX);
rotationY += Input.GetAxis("Horizontal" * Time.deltaTime;
transform.rotation = Quaternion.Euler(rotationX, rotationY, 0);
}
Example 2: unity rotation to quaternion
using UnityEngine;public class Example : MonoBehaviour
{
void Start()
{
Quaternion rotation = Quaternion.Euler(0, 30, 0);
}
}