用户工具

站点工具


侧边栏

script:unityengine:classes:transform:transform.forward

Transform.forward 向前

JavaScript ⇒ var forward: Vector3;
C# ⇒ Vector3 forward;

Description 描述

The blue axis of the transform in world space.

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

JavaScript:

	// Set's the rigidbody velocity to be 
	// along the blue axis of the transform
 
rigidbody.velocity = transform.forward * 10; 

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Example() {
        rigidbody.velocity = transform.forward * 10;
    }
}

另一个例子:

JavaScript:

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

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public float angleBetween = 0.0F;
    public Transform target;
    void Update() {
        Vector3 targetDir = target.position - transform.position;
        angleBetween = Vector3.Angle(transform.forward, targetDir);
    }
}

Transform

script/unityengine/classes/transform/transform.forward.txt · 最后更改: 2016/08/02 05:37 (外部编辑)