Пример #1
0
    public void DetachLimb(LimbSlot limb)
    {
        transform.GetChild((int)limb).GetChild(0).rotation                                           = Quaternion.identity;
        transform.GetChild((int)limb).GetChild(0).GetChild(0).rotation                               = Quaternion.identity;
        transform.GetChild((int)limb).GetChild(0).GetChild(0).GetChild(0).rotation                   = Quaternion.identity;
        transform.GetChild((int)limb).GetChild(0).GetChild(0).GetChild(0).GetChild(0).rotation       = Quaternion.identity;
        transform.GetChild((int)limb).GetChild(0).GetComponentInChildren <Rigidbody>().isKinematic   = false;
        transform.GetChild((int)limb).GetChild(0).GetComponentInChildren <CapsuleCollider>().enabled = true;
        transform.GetChild((int)limb).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetComponent <CapsuleCollider>().enabled = false;
        // transform.GetChild((int)limb).GetChild(0).GetComponent<Rigidbody>().AddForce(new Vector3(Random.Range(-10, 10), Random.Range(0, 3), Random.Range(-10, 10)));
        //  transform.GetChild((int)limb).GetChild(0).GetComponent<Limb>().Detach();
        //  transform.GetChild((int)limb).GetChild(0).GetComponent<Rigidbody>().AddForce(transform.GetChild((int)limb).GetChild(0).transform.position - transform.position);
        switch (limb)
        {
        case LimbSlot.LeftArm:
            L_Arm.GetComponent <copyPos>().other = null;                                   //_Arm;
            L_Arm.transform.GetChild(0).GetComponent <copyPos>().other             = null; //_Arm.transform.GetChild(0).gameObject;
            L_Arm.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().other = null; //L_Arm.transform.GetChild(0).GetChild(0).gameObject;
            L_Arm.GetComponent <copyPos>().copy = false;                                   //_Arm;
            L_Arm.transform.GetChild(0).GetComponent <copyPos>().copy             = false; //_Arm.transform.GetChild(0).gameObject;
            L_Arm.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().copy = false; //L_Arm.transform.GetChild(0).GetChild(0).gameObject;

            break;

        case LimbSlot.RightArm:
            R_Arm.GetComponent <copyPos>().other = null;                                   //_Arm;
            R_Arm.transform.GetChild(0).GetComponent <copyPos>().other             = null; //_Arm.transform.GetChild(0).gameObject;
            R_Arm.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().other = null; //L_Arm.transform.GetChild(0).GetChild(0).gameObject;
            R_Arm.GetComponent <copyPos>().copy = false;                                   //_Arm;
            R_Arm.transform.GetChild(0).GetComponent <copyPos>().copy             = false; //_Arm.trans
            R_Arm.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().copy = false;
            break;

        case LimbSlot.LeftLeg:
            L_Leg.GetComponent <copyPos>().other = L_Leg;
            L_Leg.transform.GetChild(0).GetComponent <copyPos>().other             = L_Leg.transform.GetChild(0).gameObject;
            L_Leg.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().other = L_Leg.transform.GetChild(0).GetChild(0).gameObject;
            break;

        case LimbSlot.RightLeg:
            R_Leg.GetComponent <copyPos>().other = R_Leg;
            R_Leg.transform.GetChild(0).GetComponent <copyPos>().other             = R_Leg.transform.GetChild(0).gameObject;
            R_Leg.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().other = R_Leg.transform.GetChild(0).GetChild(0).gameObject;
            break;
        }


        transform.GetChild((int)limb).DetachChildren();
        //AttachLimb(limb, noArm);
    }
Пример #2
0
    public void AttachLimb(LimbSlot limb, GameObject LimbType)
    {
        DetachLimb(limb);

        // transform.GetChild((int)limb).DetachChildren();
        LimbType.transform.position = transform.GetChild((int)limb).position;

        //        LimbType.transform.parent = transform.GetChild((int)limb);
        LimbType.transform.SetParent(transform.GetChild((int)limb).transform);
        LimbType.transform.parent   = transform.GetChild((int)limb);
        LimbType.transform.rotation = transform.GetChild((int)limb).rotation;
        limbCount++;
        transform.GetChild((int)limb).GetChild(0).GetComponent <Rigidbody>().isKinematic   = true;
        transform.GetChild((int)limb).GetChild(0).GetComponent <CapsuleCollider>().enabled = false;
        transform.GetChild((int)limb).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetComponent <CapsuleCollider>().enabled = true;
        switch (limb)
        {
        case LimbSlot.LeftArm:
            L_Arm.GetComponent <copyPos>().other = LimbType.transform.GetChild(0).gameObject;
            L_Arm.transform.GetChild(0).GetComponent <copyPos>().other             = LimbType.transform.GetChild(0).GetChild(0).gameObject;
            L_Arm.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().other = LimbType.transform.GetChild(0).GetChild(0).GetChild(0).gameObject;
            L_Arm.GetComponent <copyPos>().copy = true;
            L_Arm.transform.GetChild(0).GetComponent <copyPos>().copy             = true;
            L_Arm.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().copy = true;
            break;

        case LimbSlot.RightArm:
            R_Arm.GetComponent <copyPos>().other = LimbType.transform.GetChild(0).gameObject;
            R_Arm.transform.GetChild(0).GetComponent <copyPos>().other             = LimbType.transform.GetChild(0).GetChild(0).gameObject;
            R_Arm.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().other = LimbType.transform.GetChild(0).GetChild(0).GetChild(0).gameObject;
            R_Arm.GetComponent <copyPos>().copy = true;
            R_Arm.transform.GetChild(0).GetComponent <copyPos>().copy             = true;
            R_Arm.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().copy = true;
            break;

        case LimbSlot.LeftLeg:
            L_Leg.GetComponent <copyPos>().other = LimbType.transform.GetChild(0).gameObject;
            L_Leg.transform.GetChild(0).GetComponent <copyPos>().other             = LimbType.transform.GetChild(0).GetChild(0).gameObject;
            L_Leg.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().other = LimbType.transform.GetChild(0).GetChild(0).GetChild(0).gameObject;
            break;

        case LimbSlot.RightLeg:
            R_Leg.GetComponent <copyPos>().other = LimbType.transform.GetChild(0).gameObject;
            R_Leg.transform.GetChild(0).GetComponent <copyPos>().other             = LimbType.transform.GetChild(0).GetChild(0).gameObject;
            R_Leg.transform.GetChild(0).GetChild(0).GetComponent <copyPos>().other = LimbType.transform.GetChild(0).GetChild(0).GetChild(0).gameObject;
            break;
        }
    }