Example #1
0
 public void checkNewCollision(Collision2D other)
 {
     if (myType != platformType.disabled)
     {
         Rigidbody2D rb = other.gameObject.GetComponent <Rigidbody2D>();
         if (rb != null)
         {
             Debug.Log(other.gameObject.name + " new col check1 - velocity: " + rb.velocity.y);
             if (!rb.isKinematic && rb.simulated && rb.IsAwake() && other.gameObject.transform.position.y > gameObject.transform.position.y)// && rb.velocity.y <= 0)
             {
                 Debug.Log(other.gameObject.name + " new col check2, does it need script?");
                 moveObjectsOnTopV2 script = other.gameObject.GetComponent <moveObjectsOnTopV2>();
                 if (script == null)
                 {
                     Debug.Log(other.gameObject.name + " is getting the script from " + gameObject.name);
                     script = other.gameObject.AddComponent(typeof(moveObjectsOnTopV2)) as moveObjectsOnTopV2;
                     script.setAddedDynamically(true);
                     script.myType = platformType.moveWithPlatform;
                     if (myType == platformType.moveWithPlatform)
                     {
                         script.joint = other.gameObject.AddComponent(typeof(FixedJoint2D)) as FixedJoint2D;
                         script.joint.connectedBody = gameObject.GetComponent <Rigidbody2D>();
                         script.joint.breakForce    = breakForce;
                         script.joint.breakTorque   = breakTorque;
                     }
                 }
             }
         }
     }
 }
Example #2
0
 private void OnCollisionExit2D(Collision2D other)
 {
     if (other.gameObject.transform.position.y > gameObject.transform.position.y)
     {
         moveObjectsOnTopV2 script = other.gameObject.GetComponent <moveObjectsOnTopV2>();
         if (script != null)
         {
             if (script.addedDynamically)
             {
                 Destroy(script);
                 Debug.Log(other.gameObject.name + " is losing its script from " + gameObject.name);
             }
         }
     }
 }