Overview: Common Operations 常用操作

Most game object manipulations are done either through the game object's Transform and/or Rigidbody. These are accessible inside behaviour scripts through the member variables transform and rigidbody respectively. So if you wanted to rotate an object 5 degrees around its Y axis every frame you could write the following:

很多对游戏对象的操作都是通过修改游戏物体的 Transform (转换)和/或 Rigidbody (刚体).这通过修改脚本里的成员变量transform和rigidbody很容易去实现.如果你想要物体每帧在Y轴上旋转5度,你可以这样写:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Update() {
		transform.Rotate(0, 5, 0);
	}
}

function Update() {
	transform.Rotate(0, 5, 0);
}

If you want to move an object forward you would write this:

如果你想向前移动你的物体,你可以这样写:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Update() {
		transform.Translate(0, 0, 2);
	}
}
function Update() {
	transform.Translate(0, 0, 2);
}
最后修改:2010年11月30日 Tuesday 22:52

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。