set rotation unity code example
Example 1: how to just aet z rotation on transform unity
transform.rotation = Quaternion.Euler(0, 90, 0);
Example 2: 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 3: unity set position
GameObject.transform.position = new Vector3(x, y, z);
Example 4: unity how to change rotation
transform.eulerAngles = new Vector3(0f, 180f, 0f);
Example 5: set rotation to velocity unity
transform.rotation = Quaternion.LookRotation(rigidbody.velocity);