Transform.forward 向前


var forward : Vector3

Description描述

The blue axis of the transform in world space.

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

  • C#

  • JavaScript

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;

另一个例子:

  • C#

  • JavaScript

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);}


,