void LateUpdate() { PlayerMovement pm = player.GetComponent <PlayerMovement>(); foreach (AABB box in platforms) { if (player.OverlapCheck(box)) { pm.ApplyFix(player.FindFix(box)); } } foreach (AABB power in powerups) { if (player.OverlapCheck(power)) { //player collides with powerup! // do something SpringBlock sb = power.GetComponent <SpringBlock>(); if (sb) { sb.PlayerHit(pm); } } } }
void LateUpdate() { if (!player) { return; // no player, do not do collision detection } PlayerMovement pm = player.GetComponent <PlayerMovement>(); // checking collision between and Player and the platforms foreach (AABB box in platforms) { if (player.OverlapCheck(box)) { // move player out of the platf pm.ApplyFix(player.FindFix(box)); } } // checking collsion with players and any of the overlap objects foreach (AABB power in powerups) { if (player.OverlapCheck(power)) { //player collides with powerup! // do something SpringBlock sb = power.GetComponent <SpringBlock>(); if (sb) { sb.PlayerHit(pm); } OverlapObject oo = power.GetComponent <OverlapObject>(); if (oo) { oo.OnOverlap(pm); } } } }