コード例 #1
0
    protected void detachShipPartsAsDebris()
    {
        ShipPart shipPart = null;
        GameObject newDebris = null;
        GameObject newDebrisShipPart = null;
        while (equipment.Length>0)
        {
            shipPart = equipment[0].getShipPart();
            if (shipPart)
            {
                newDebris = new GameObject("ShipDebris");
                newDebris.tag = "ObjectInSpace";
                newDebris.AddComponent<Rigidbody>();
                newDebris.AddComponent<ObjectInSpace>();
                newDebris.transform.position = shipPart.gameObject.transform.position;

                newDebrisShipPart = new GameObject("ShipParts");
                newDebrisShipPart.transform.parent = newDebris.transform;

                shipPart.gameObject.transform.parent = newDebrisShipPart.transform;

                newDebris.GetComponent<ObjectInSpace>().niceName = "ShipDebris";
                newDebris.GetComponent<ObjectInSpace>().isDebris = true;
                newDebris.GetComponent<ObjectInSpace>().canBeTargetted = true;
                newDebris.GetComponent<ObjectInSpace>().canBeDamaged = true;
                newDebris.GetComponent<ObjectInSpace>().initialProperties = new InitialProperties();
                newDebris.GetComponent<ObjectInSpace>().initialProperties.enable = true;
                newDebris.GetComponent<ObjectInSpace>().initialProperties.maxHull = 500f;
                newDebris.GetComponent<ObjectInSpace>().initialProperties.mass = equipment[0].getMass();
                newDebris.GetComponent<ObjectInSpace>().initialProperties.drag = 1f;
                newDebris.GetComponent<ObjectInSpace>().initialProperties.dragAngular = 1f;

                newDebris.GetComponent<Rigidbody>().AddForce((newDebris.transform.position - transform.position).normalized * Random.Range(4000f, 7000f));

                shipPart.shutDown();
                removeEquipment(equipment[0]);
            }
        }
    }