void Update()
{
PlatformCanDrop dropRef = gameObject.GetComponent<PlatformCanDrop>();
isClose = false;
Collider2D[] allColliders = Physics2D.OverlapAreaAll(topL, botR);
foreach (Collider2D thatCollider in allColliders){
if (thatCollider.gameObject == playerObject)
isClose = true;
}
if (isClose) {
float minx = platX - (width / 2.0f) + (platBox.localScale.x * platColCntr.x);
float maxx = platX + (width / 2.0f) + (platBox.localScale.x * platColCntr.x);
float maxy = platY + (height / 2.0f)+ (platBox.localScale.y * platColCntr.y);
float miny = platY - (height / 2.0f) + (platBox.localScale.y * platColCntr.y);
BoxCollider2D playerBox = playerObject.GetComponent<BoxCollider2D>();
float psX = playerObject.transform.localScale.x;
float psY = playerObject.transform.localScale.y;
float poX = playerObject.transform.position.x;
float poY = playerObject.transform.position.y;
float pminx = poX - ((playerBox.size.x * psX) / 2.0f) + playerBox.center.x;
float pminy = poY - ((playerBox.size.y * psY) / 2.0f) + playerBox.center.y;
float pmaxx = poX + ((playerBox.size.x * psX) / 2.0f) + playerBox.center.x;
float pmaxy = poY + ((playerBox.size.y * psY) / 2.0f) + playerBox.center.y;
under = (pmaxy < maxy);
over = (pminy > maxy);
left = (pmaxx < minx);
right = (pminx > maxx);
if(dropRef.dropping && over && !left && !right) // this allows drop-down platforms to work on all one ways
{ Ghost();
dropRef.dropping = false;
}
else
switch (whichWay){
case "up":
if(under && !left && !right)
Ghost();
else if(over || right || left)
StopGhost();
break;
case "down":
if(over && !left && !right)
Ghost();
else if(under || right || left)
StopGhost();
break;
case "right":
if(left && !over && !under)
Ghost();
else if(right || under || over)
StopGhost();
break;
case "left":
if(right && !over && !under)
Ghost();
else if(left || under || over)
StopGhost();
break;
default:
Debug.Log("which way match case var wrong, default case happened");
break;
}
}
//if (!isClose)
// this.enabled = false;
}