GameObject.CreatePrimitive 创建基本物体

static function CreatePrimitive (type : PrimitiveType) : GameObject

Description描述

Creates a game object with a primitive mesh renderer and appropriate collider.

创建一个带有基本网格渲染器和相应碰撞器的游戏物体。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Start() {
		GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
		GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
		cube.transform.position = new Vector3(0, 0.5F, 0);
		GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
		sphere.transform.position = new Vector3(0, 1.5F, 0);
		GameObject capsule = GameObject.CreatePrimitive(PrimitiveType.Capsule);
		capsule.transform.position = new Vector3(2, 1, 0);
		GameObject cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
		cylinder.transform.position = new Vector3(-2, 1, 0);
	}
}
//在场景中创建一个平面,球体,立方体,胶囊,圆柱体
function Start () {
var plane : GameObject = GameObject.CreatePrimitive(PrimitiveType.Plane);

var cube : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = Vector3(0, 0.5, 0);

var sphere : GameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = Vector3(0, 1.5, 0);

var capsule : GameObject = GameObject.CreatePrimitive(PrimitiveType.Capsule);
capsule.transform.position = Vector3(2, 1, 0);

var cylinder : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
cylinder.transform.position = Vector3(-2, 1, 0);
}
最后修改:2011年7月14日 Thursday 10:20

本脚本参考基于Unity 3.4.1f5

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