如何统一旋转 2D 对象 90 度
我需要将 2D GameObject 按 z 轴旋转 90 度。所以我已经尝试过 transform.RotateAround
但仍然旋转一整圈:
transform.RotateAround(target.transform.position, new Vector3 (0, 0, -90),
50f * Time.deltaTime)
我需要将其停止 90 度。我该怎么做?
I need to rotate 2D GameObject
by 90 degrees by z axis. So I already tried transform.RotateAround
but still rotates in a complete circle:
transform.RotateAround(target.transform.position, new Vector3 (0, 0, -90),
50f * Time.deltaTime)
I need to stop it by 90. How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个基于
deltaTime
旋转并跟踪的 协程旋转了多远,一旦到达90
就停止。使用 Mathf.Min 确保旋转不超过 90。然后,当您想要开始旋转时,如果协程尚未旋转,则启动协程:
保存协程本身而不是使用旗帜。这使您可以执行诸如随时停止旋转之类的操作。
Create a coroutine that rotates based on
deltaTime
and keeps track of how far it has rotated, stopping once it hits90
. UseMathf.Min
to be sure not to rotate past 90.Then when you want to start rotating, start the coroutine if it isnt already rotating:
It's slightly better form to save the Coroutine itself instead of using a flag. This lets you do stuff like stop the rotation at any point.