void OnCollisionEnter2D(Collision2D col) { // do this check so the collision is only called once - failsafe against unity physics engine if (_isColliding) { return; } _isColliding = true; // only check for collisions with the player is the steel crate's gravity is enabled if (gravEnabled && col.gameObject.CompareTag("Player")) { Transform groundCheck = col.gameObject.transform.GetChild(0); Vector2 posOffset = (Vector2)transform.position + PhysicsUtilities.OffsetToEdgeRenderer(rend); // NEED TO FIND OUT HOW TO NOT DESTROY INSTANTLY WHILE IN GRAV TRANSITION // FOR SOME REASON THE BELOW DOES NOT WORK if (!GameController.gravTransitionState && PhysicsUtilities.IsBelow(groundCheck.position, posOffset)) { Destroy(col.gameObject); } // to be added: enter gameover state } // handle check for glass if (isGlass && GameController.gravTransitionState) { if (_glass.CollisionHandler(rend)) { Destroy(gameObject); } } }
// if we are glass, handle glass collisions void OnCollisionEnter2D() { if (isGlass) { if (glass.CollisionHandler(rend)) { Destroy(gameObject); } } }