UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Transform.right
# [Transform](https://docs.unity3d.com/cn/2019.4/ScriptReference/Transform.html).right public [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **right** ; ## 描述 世界空间中变换的红轴。 操作游戏对象在世界空间中变换的 X 轴(红轴)上的位置。与 [Vector3.right](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3-right.html) 不同,[Transform.right](https://docs.unity3d.com/cn/2019.4/ScriptReference/Transform-right.html) 在移动游戏对象的同时,还考虑其旋转。 旋转游戏对象时,表示游戏对象的 X 轴的红色箭头也会改变方向。[Transform.right](https://docs.unity3d.com/cn/2019.4/ScriptReference/Transform-right.html) 沿红色箭头所在的轴 (X) 移动游戏对象。 要在沿 X 轴移动 GameObject 时忽略旋转,请参阅 [Vector3.right](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3-right.html)。 ``` //Attach this script to a GameObject with a Rigidbody2D component. Use the left and right arrow keys to see the transform in action. //Use the up and down keys to change the rotation, and see how using Transform.right differs from using Vector3.right using UnityEngine; public class Example : MonoBehaviour { Rigidbody2D m_Rigidbody; float m_Speed; void Start() { //Fetch the Rigidbody component you attach from your GameObject m_Rigidbody = GetComponent<Rigidbody2D>(); //Set the speed of the GameObject m_Speed = 10.0f; } void Update() { if (Input.GetKey(KeyCode.RightArrow)) { //Move the Rigidbody to the right constantly at speed you define (the red arrow axis in Scene view) m_Rigidbody.velocity = transform.right * m_Speed; } if (Input.GetKey(KeyCode.LeftArrow)) { //Move the Rigidbody to the left constantly at the speed you define (the red arrow axis in Scene view) m_Rigidbody.velocity = -transform.right * m_Speed; } if (Input.GetKey(KeyCode.UpArrow)) { //rotate the sprite about the Z axis in the positive direction transform.Rotate(new Vector3(0, 0, 1) * Time.deltaTime * m_Speed, Space.World); } if (Input.GetKey(KeyCode.DownArrow)) { //rotate the sprite about the Z axis in the negative direction transform.Rotate(new Vector3(0, 0, -1) * Time.deltaTime * m_Speed, Space.World); } } } ```
da
2022年6月21日 11:33
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码