Version: 2017.1
public static Quaternion LookRotation (Vector3 forward, Vector3 upwards= Vector3.up);

参数

forward 要查看的方向。
upwards 定义向上方向的向量。

描述

使用指定的 forwardupwards 方向创建旋转。

返回计算的四元数。 如果用于对变换进行定向,Z 轴将与 forward 对齐, Y 轴与 upwards 对齐(如果这些向量是正交的)。 如果前进方向为零,则记录错误。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform target; void Update() { Vector3 relativePos = target.position - transform.position; Quaternion rotation = Quaternion.LookRotation(relativePos); transform.rotation = rotation; } }

另请参阅:SetLookRotation

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961