UnityScript (JS) 對照 C#
範例一
#pragma strict
// UnityScript
class Person { var transform : Transform;
var name : String;
var height : int;
function Goto(position : Vector3) {
transform.position = position;
}
// C#
public class Person
{
public Transform transform;
public string name;
public int height;
public void Goto(Vector3 position)
{
transform.position = position;
}
}
範例二
// UnityScript
// File: OffsetExample.js
#pragma strict
var position : Vector3;
var yOffset : float;
function GetOffsetPosition() : Vector3 {
var p : Vector3 = transform.position;
return Vector3(p.x, p.y + yOffset, p.z);
}
// C#
public class OffsetExample : MonoBehaviour
{
public Vector3 position;
public float yOffset;
public Vector3 GetOffsetPosition()
{
// 等同 Vector3 p = transform.position;
var p = transform.position;
return new Vector3(p.x, p.y + yOffset, p.z);
}
}