物体变成其他物体的子物体
var attach : boolean;
var player : Transform;
var shootspeed : float=10;
function Start()
{
    collider.isTrigger = false;
};
function OnCollisionEnter(collision : Collision)
{
    if (collision.gameObject.tag=="Player")
    {
        attach=true;
        player=collision.transform;
        if (rigidbody)   Destroy (rigidbody);
        transform.parent=player;                                          //物体变成其他物体的子物体
        transform.localPosition=Vector3(0,-0.65,5);
    };
};
function Update ()
{
    if(Input.GetKeyDown(KeyCode.F))
    {
        if (transform.parent)
        {
            transform.parent=null;
            gameObject.AddComponent ("Rigidbody");
            rigidbody.velocity = rigidbody.velocity + player.TransformDirection(Vector3.forward)*shootspeed;
            attach=false;
        };
    };
}
本条目发布于2010年2月20日。属于Unity脚本分类。