示例#1
0
文件: Part.cs 项目: r2d2m/creasiege
    // Destroy only this part and move other parts in new empty gameobjects
    public void Destroy()
    {
        Detach();
        Debris debris = null;
        Part   part   = null;

        foreach (PartJoint joint in m_joints)
        {
            if (joint != m_rootJoint && joint.connection != null && joint.connection.part != null)
            {
                part   = joint.connection.part;
                debris = Instantiate(DataManager.instance.prefabDebris,
                                     part.transform.position, part.transform.rotation);
                part.SetParentRecursively(debris.transform);

                debris.ComputeCenterOfMass();
                ApplyExplosion(debris.GetComponent <Rigidbody>());
            }
        }

        VehicleEditorController vehicle = transform.root.GetComponent <VehicleEditorController>();
        Debris deb = transform.root.GetComponent <Debris>();

        if (vehicle != null)
        {
            vehicle.ComputeCenterOfMass();
            ApplyExplosion(vehicle.GetComponent <Rigidbody>());
        }
        else if (deb != null)
        {
            deb.ComputeCenterOfMass();
            ApplyExplosion(deb.GetComponent <Rigidbody>());
        }

        Debug.Log("Explode");
        Instantiate(DataManager.instance.prefabExplosion, transform.position, Quaternion.identity);

        onDestroy.Invoke();
        Destroy(gameObject);
    }