简体   繁体   English

如何在Unity中将相机视图旋转回正常状态?

[英]How do I rotate my camera view back to normal in Unity?

In my app, I have an option to reset the user's view. 在我的应用程序中,我可以选择重置用户的视图。
It takes the camera position back to the initial position, say (0,0,0). 它将摄像机位置返回到初始位置,例如(0,0,0)。 However, if before clicking on reset, the user had rotated the view of the camera (I have certain mouse actions to rotate the camera), after clicking on reset, the camera position goes back to (0,0,0) but the rotation remains the same. 但是,如果在单击“重置”之前,用户已经旋转了摄像机的视图(我有某些鼠标动作来旋转摄像机),则在单击“重置”之后,摄像机的位置返回到(0,0,0),但是旋转保持原样。

How do I rotate it back to normal? 如何将其旋转回正常状态? (Where normal is in a completely un-rotated state, viewing straight ahead) (在正常情况下完全处于未旋转状态,直视前方)

It means you reset the position, but not the rotation. 这意味着您要重置位置,而不是旋转位置。

To reset the rotation: 重置旋转:

_yourCamera.transform.rotation = Quarterion.identity;

You can also use the property of the main camera if we're talking about the camera tagged as "Main". 如果我们谈论的是标记为“主”的摄像机,则也可以使用主摄像机的属性。

Camera.main.transform.rotation = Quarterion.identity;

You could use the "lookAt" transform method to rotate your camera and look again to the object you had initially. 您可以使用“ lookAt”变换方法来旋转相机,然后再次查看您最初拥有的对象。

// Rotate the camera every frame so it keeps looking at the target
transform.LookAt(target);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM