示例#1
0
    public void AddToInventory(GameObject debris)
    {
        DebrisStructure debrisStructure = new DebrisStructure();
        Debris          debnfo          = debris.GetComponent <Debris>();

        debrisStructure.score  = debnfo.pointvalue;
        debrisStructure.sprite = debnfo.GetComponent <SpriteRenderer>().sprite;
        inventorylist.Add(debrisStructure);
    }
示例#2
0
    public void OnExplode()
    {
        Transform t = transform;

        for (int i = 0; i < totalDebris; i++)
        {
            t.TransformPoint(0, -100, 0);
            Debris      clone  = Instantiate(debris, t.position, Quaternion.identity);
            Rigidbody2D body2D = clone.GetComponent <Rigidbody2D>();
            body2D.AddForce(Vector3.right * Random.Range(-1000, 1000));
            body2D.AddForce(Vector3.up * Random.Range(500, 2000));
        }

        Destroy(gameObject);
    }
示例#3
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);
    }