您的位置:首页 > 其它

添加组件或脚本的方法

2016-04-08 14:39 309 查看
1.在Inspctor面板上直接添加

2.使用AddComponent添加组件

public SphereCollider sc;
public void Awake() {

//给游戏物体添加名为FoobarScript的脚本
gameObject.AddComponent("FoobarScript");
//给游戏物体添加球体碰撞器
sc = gameObject.AddComponent("SphereCollider") as SphereCollider;}
3.RequireComponent需要组件

将需要添加的组件放到命名空间下面类上面,将脚本放到需要添加的物体上,组件就会自动添加

using UnityEngine;

using System.Collections;

   [RequireComponent(typeof(Rigidbody))]

public class qw : MonoBehaviour {

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: