void AttemptToMove(Vector3 direction) { RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, 1); if (hit.collider == null) { lerpMovement.MoveBy(direction); } else if (hit.collider.tag == "Movable") { var movableObject = hit.transform.GetComponent <MovableObject>(); if (movableObject != null) { if (movableObject.AttemptPush(direction)) { lerpMovement.MoveBy(direction); } } } }
public bool AttemptPush(Vector3 direction) { if (!lerpMovement.isMoving) { RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, 1); if (hit.collider == null) { lerpMovement.MoveBy(direction); if (currentGoal != null) { if (OnUnsatisfyGoal != null) { OnUnsatisfyGoal(currentGoal); } } return(true); } } return(false); }