Unity3d transform
using UnityEngine; using System.Collections; public class transform : MonoBehaviour { // Use this for initialization void Start () { //获取当前脚本所挂载的游戏对象身上的Transform //控制游戏对象的位置、选择、缩放 Vector3 pos = transform.position;//世界坐标位置 print(pos); Vector3 local_pos = transform.localPosition; print(local_pos); //一般不直接修改四元数 //transform.rotation; //transform.localRotation; //localScale:控制游戏对象的缩放 Vector3 vScale = transform.localScale; //控制游戏对象间的父子关系 Transform parent = transform.parent; //当前游戏对象的根对象 Transform root = transform.root; //获取当前游戏对象的子对象Cube Transform child_ = transform.Find("Cube"); Transform child = transform.FindChild("Cube"); } // Update is called once per frame void Update () { if(Input.GetKeyDown(KeyCode.P)) { //transform.position = Vector3.zero; //transform.localScale = new Vector3(1f, 2f, 1f); //改变当前游戏对象位置 //transform.Translate(new Vector3(1f, 0, 0)); //控制当前游戏对象旋转 //transform.Rotate(Vector3.up, 10f);//以Vector3.up位轴心旋转10度 transform.eulerAngles = new Vector3(0, 45, 0); } } }