Quaternion.FromToRotation
public static Quaternion FromToRotation (Vector3 fromDirection, Vector3 toDirection);
描述
创建一个从 fromDirection
旋转到 toDirection
的旋转。
通常情况下,您使用该方法对变换进行旋转,使其的一个轴(例如 Y 轴)跟随世界空间中的目标方向 /toDirection/。
using UnityEngine; public class Example : MonoBehaviour { void Start() { // Sets the rotation so that the transform's y-axis goes along the z-axis transform.rotation = Quaternion.FromToRotation(Vector3.up, transform.forward); } }