Exemplo n.º 1
0
    public static void UnBind(PhysicsModifyable pM1, PhysicsModifyable pM2)
    {
        PhysicsAffected pA1 = pM1.GetComponent <PhysicsAffected>();
        PhysicsAffected pA2 = pM2.GetComponent <PhysicsAffected>();

        if (pA1 != null && pA2 != null)
        {
            if (pA1.GetComponent <FixedJoint>() != null)
            {
                Destroy(pA1.GetComponent <FixedJoint>());
            }

            if (pA2.GetComponent <FixedJoint>() != null)
            {
                Destroy(pA2.GetComponent <FixedJoint>());
            }
        }
        else if (pA1 != null || pA2 != null)
        {
            if (pA1 != null)
            {
                pA1.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
            }
            else if (pA2 != null)
            {
                pA2.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
            }
        }
    }
Exemplo n.º 2
0
    public static void Bind(PhysicsModifyable pM1, PhysicsModifyable pM2)
    {
        PhysicsAffected pA1 = pM1.GetComponent <PhysicsAffected>();
        PhysicsAffected pA2 = pM2.GetComponent <PhysicsAffected>();

        if (pA1 != null && pA2 != null)
        {
            FixedJoint j1 = pA1.GetComponent <FixedJoint>();
            if (j1 == null || j1.connectedBody != pA2.GetComponent <Rigidbody>())
            {
                if (j1 != null)
                {
                    Destroy(j1);
                }

                j1 = pA1.gameObject.AddComponent <FixedJoint>();
                j1.connectedBody = pA2.GetComponent <Rigidbody>();
            }

            FixedJoint j2 = pA2.GetComponent <FixedJoint>();
            if (j2 == null || j2.connectedBody != pA1.GetComponent <Rigidbody>())
            {
                if (j2 != null)
                {
                    Destroy(j2);
                }

                j2 = pA2.gameObject.AddComponent <FixedJoint>();
                j2.connectedBody = pA1.GetComponent <Rigidbody>();
            }
        }
        else if (pA1 != null || pA2 != null)
        {
            if (pA1 != null)
            {
                pA1.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            }
            else if (pA2 != null)
            {
                pA2.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            }
        }
    }