private void OnCollisionExit2D(Collision2D other) { if (other.gameObject.transform.position.y > gameObject.transform.position.y) { movePlayerOnTop script = other.gameObject.GetComponent <movePlayerOnTop>(); if (script != null) { if (script.addedDynamically) { Destroy(script); Debug.Log(other.gameObject.name + " is losing its script from " + gameObject.name); } } } }
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?"); movePlayerOnTop script = other.gameObject.GetComponent <movePlayerOnTop>(); CharacterController2D contScript = other.gameObject.GetComponent <CharacterController2D>(); //Make sure we're not adding the script to our player if (script == null && contScript == null) { Debug.Log(other.gameObject.name + " is getting the script from " + gameObject.name); script = other.gameObject.AddComponent(typeof(movePlayerOnTop)) as movePlayerOnTop; script.setAddedDynamically(true); script.myType = platformType.moveWithPlatform; } } } } }