Transform.forward 向前

var forward : Vector3

Description描述

The blue axis of the transform in world space.

在世界空间坐标变换的蓝色轴。也就是z轴。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public void Awake() {
		rigidbody.velocity = transform.forward * 10;
	}
}
// Set's the rigidbody velocity to be
// along the blue axis of the transform
//设置刚体的速度沿着物体的蓝色轴移动
rigidbody.velocity = transform.forward * 10;

另一个例子:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public float angleBetween = 0.0F;
	public Transform target;
	void Update() {
		Vector3 targetDir = target.position - transform.position;
		angleBetween = Vector3.Angle(transform.forward, targetDir);
	}
}
// Computes the angle between the target transform and this object
//计算目标变换和这个物体之间的角度
var angleBetween = 0.0;
var target : Transform;
function Update () {
	var targetDir = target.position - transform.position;
	angleBetween = Vector3.Angle (transform.forward, targetDir);
}
最后修改:2011年1月16日 Sunday 17:54

本脚本参考基于Unity 3.4.1f5

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