Vector3 targetPosition = new Vector3(-1f, 0f, 1f); Vector3 direction = (targetPosition - transform.position).normalized; Quaternion targetRotation = Quaternion.LookRotation(direction, Vector3.up); transform.rotation = targetRotation;
float angle = 45f; Vector3 axis = Vector3.up; Quaternion rotation = Quaternion.Euler(axis * angle); transform.rotation = rotation;This code rotates the game object by 45 degrees around the y-axis using the Quaternion.Euler method, which takes in a vector representing the angle to rotate each axis by. The resulting quaternion is then assigned to the game object's rotation. Package/library: UnityEngine.