I wrote a code block to rotate the main camera. However, the result is not what I want.
public Transform mainCamera;
public Vector3 toVector;
public float speed;
private float timeCount = 0.0f;
private Quaternion from;
private Quaternion to;
private void Awake()
{
mainCamera = GameObject.FindGameObjectWithTag("MainCamera").transform;
}
private void OnEnable()
{
from = mainCamera.localRotation;
to = Quaternion.Euler(toVector);
}
void Update()
{
mainCamera.localRotation = Quaternion.Slerp(from, to, timeCount);
timeCount = timeCount + speed * Time.deltaTime;
if (timeCount > 1.0f)
{
timeCount = 0.0f;
this.enabled = false;
}
}
Result;
How to fix it?