纳金网

标题: 怎么用 脚本 添加 BoxCollider ? [打印本页]

作者: star-小虎    时间: 2013-10-22 14:05
标题: 怎么用 脚本 添加 BoxCollider ?
  一直没找到。。不好意思呀 发现官方对脚本的教程好少

作者: huhumark    时间: 2013-10-22 16:52
我也在找哦
作者: dihcro    时间: 2013-10-22 23:29
using UnityEngine;
using System.Collections;

public class addboxcollider2 : MonoBehaviour {

        // Use this for initialization
        void Start ()
        {
                gameObject.AddComponent(typeof(BoxCollider));
        }
       
        // Update is called once per frame
        void Update () {
       
        }
}

作者: dihcro    时间: 2013-10-22 23:31
还有一种,你添加脚本时自动添加collide
using UnityEngine;
using System.Collections;

[RequireComponent(typeof(BoxCollider))]
public class addboxcollider : MonoBehaviour {

       
}
作者: dihcro    时间: 2013-10-23 00:33
using UnityEngine;
using System.Collections;

public class addboxcollider2 : MonoBehaviour {

        // Use this for initialization
        void Start ()
        {
                gameObject.AddComponent(typeof(BoxCollider));
        }
       
       
}

作者: herry7x    时间: 2013-10-23 09:17
BoxCollider box = this.gameObject.AddComponent<BoxCollider>();
给你需要加BoxCollider的gameObject上添加一个
作者: huhumark    时间: 2013-10-26 21:55
谢谢了,还有强类型的方法




欢迎光临 纳金网 (http://wwww.narkii.com/club/) Powered by Discuz! X2.5