C# 对象旋转完成后,如何在两个摄影机之间切换?
我在旋转开始之前切换摄像机,我需要的是在旋转结束时切换摄像机。不是在旋转开始后,而是在旋转结束时。因为您知道要在哪个旋转结束,所以可以在达到该旋转后更换相机 在更新方法之外创建并初始化变量:C# 对象旋转完成后,如何在两个摄影机之间切换?,c#,unity3d,C#,Unity3d,我在旋转开始之前切换摄像机,我需要的是在旋转结束时切换摄像机。不是在旋转开始后,而是在旋转结束时。因为您知道要在哪个旋转结束,所以可以在达到该旋转后更换相机 在更新方法之外创建并初始化变量: if (rotateHead == true) { cameras[0].SetActive(false); cameras[1].SetActive(true); anim.enable
if (rotateHead == true)
{
cameras[0].SetActive(false);
cameras[1].SetActive(true);
anim.enabled = false;
head.transform.localRotation = Quaternion.Lerp(head.transform.localRotation, Quaternion.Euler(head.transform.localRotation.x, head.transform.localRotation.y, 0f), 1.0f * Time.deltaTime);
}
然后检查更新方法中的回合是否完成,如果完成,则更换摄影机:
private bool isFinishedTurning = false;
private bool isFinishedTurning = false;
if (rotateHead == true) {
Quaternion targetRotation = Quaternion.Euler(head.transform.localRotation.x, head.transform.localRotation.y, 0f);
head.transform.localRotation = Quaternion.Lerp(head.transform.localRotation, targetRotation, 1.0f * Time.deltaTime);
// Check whether the current localRotation is the same as the target rotation
if (head.transform.localRotation == targetRotation) {
isFinishedTurning = true;
}
}
// If the rotation is complete, swap cameras and disable animation
if (isFinishedTurning == true) {
cameras[0].SetActive(false);
cameras[1].SetActive(true);
anim.enabled = false;
isFinishedTurning = false;
}