UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Transform.LookAt
# [Transform](https://docs.unity3d.com/cn/2019.4/ScriptReference/Transform.html).LookAt public void **LookAt** ([Transform](https://docs.unity3d.com/cn/2019.4/ScriptReference/Transform.html) **target**); public void **LookAt** ([Transform](https://docs.unity3d.com/cn/2019.4/ScriptReference/Transform.html) **target**, [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **worldUp**= Vector3.up); ## 参数 | target | 要指向的对象。 | | --------- | ---------------------- | | worldUp | 指定向上方向的矢量。 | ## 描述 旋转变换,使向前矢量指向 `target` 的当前位置。 随后它会旋转变换以将其向上方向矢量指向 `worldUp` 矢量暗示的方向。 如果省略 `worldUp` 参数,则该函数会使用世界空间 y 轴。如果向前方向垂直于 `worldUp`,则旋转的向上矢量将仅匹配 `worldUp` 矢量。 ``` using UnityEngine; // This complete script can be attached to a camera to make it // continuously point at another object. public class ExampleClass : MonoBehaviour { public Transform target; void Update() { // Rotate the camera every frame so it keeps looking at the target transform.LookAt(target); // Same as above, but setting the worldUp parameter to Vector3.left in this example turns the camera on its side transform.LookAt(target, Vector3.left); } } ``` --- public void **LookAt** ([Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **worldPosition**); public void **LookAt** ([Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **worldPosition**, [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **worldUp**= Vector3.up); ## 参数 | worldPosition | 要对准的点。 | | --------------- | ---------------------- | | worldUp | 指定向上方向的矢量。 | ## 描述 旋转变换,使向前矢量指向 /worldPosition/。 随后它会旋转变换以将其向上方向矢量指向 `worldUp` 矢量暗示的方向。 如果省略 `worldUp` 参数,则该函数会使用世界空间 y 轴。如果向前方向垂直于 `worldUp`,则旋转的向上矢量将仅匹配 `worldUp` 矢量。 ``` using UnityEngine; public class ExampleClass : MonoBehaviour { public Transform target; void Update() { // Point the object at the world origin (0,0,0) transform.LookAt(Vector3.zero); } } ```
da
2022年6月21日 11:37
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码