在这里找到了这个答案: Rotate a gameobject in Unity
我发现这非常有用,但我只想将旋转分配给 Z 轴,但我无法正常工作。
using UnityEngine;
using System.Collections;
public class Rotation : MonoBehaviour {
public GameObject Player;
public GameObject PlayerCube;
// Use this for initialization
void Start () {
var playerMapPos = Player;
var playerWorldPos = PlayerCube;
PlayerCube.transform.rotation = Player.transform.rotation;
}
// Update is called once per frame
void Update () {
}
}
最佳答案
要限制旋转轴,您需要使用欧拉角而不是四元数。首先,将旋转四元数转换为欧拉角,然后根据需要修改旋转(将除 y 之外的所有轴指定为 0),然后再转换回来。
关于c# - 仅在 Z 轴上旋转游戏对象 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30074135/