
本文3D天堂将详细介绍转换工具,将会看到如何使用转换工具和脚本更改游戏对象的转换, 以下是本文介绍的几个内容:
变换工具
变换工具用于移动、旋转、缩放或矩形变换场景中选定的游戏对象,转换工具位于Unity界面工具栏部分的最左侧。

手工具

Hand工具不用于更改游戏对象的变换,它仅用于场景的左右上下移动导航。
如下所示:

移动工具
默认情况下,会在unity软件中选择移动转换。

使用此工具更改游戏对象的位置,最后更改的轴将以黄色显示。
如下所示:

旋转工具

使用旋转工具改变游戏对象的旋转角度,最后更改的轴将以黄色显示。
如下所示:

缩放工具

使用缩放工具更改游戏对象的大小,最后更改的轴将以黄色显示。
如下所示:

矩形变换

矩形变换主要用于定位UI元素或2D元素,但也可以使用此工具操作3D对象,可以使用此工具更改游戏对象的比例。
如下所示:

在变换工具之间切换的键盘快捷键
使用下面给定的热键在转换工具之间切换:
- Q → 手动工具
- W → 移动
- E → 旋转
- R → 缩放
- T → 矩形变换
在运行时更改游戏对象的变换
获取GameObject的变换组件并使用脚本更改其位置、旋转和缩放。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TransformDemo : MonoBehaviour {
// Use this for initialization
void Start () {
// change position of the GameObject
Debug.Log("Previous Position: " + GetComponent<Transform> ().position);
GetComponent<Transform> ().position = new Vector3 (2.0f, 0.0f, 0.0f);
Debug.Log("New Position: " + GetComponent<Transform> ().position);
// change rotation of the GameObject using Euler Angle
Debug.Log("Previous Rotation: " + GetComponent<Transform> ().eulerAngles);
GetComponent<Transform> ().eulerAngles = new Vector3 (90.0f, 0.0f, 0.0f);
Debug.Log("New Rotation: " + GetComponent<Transform> ().eulerAngles);
// Change scale of of the GameObject
Debug.Log("Previous Scale: " + GetComponent<Transform> ().localScale);
GetComponent<Transform> ().localScale = new Vector3 (2.0f, 2.0f, 2.0f);
Debug.Log("New Scale: " + GetComponent<Transform> ().localScale);
}
// Update is called once per frame
void Update () {
}
}
在控制台显示的结果:

…
以上是3D天堂关于学习Unity中的转换工具的全部内容,如果你有任何反馈,请随时在本页面下方留言。