protected bool CanMove(BaseTile tile, int xDir, int zDir) { bool canMove = true; foreach (BaseUnit u in tile.OccupyingUnits(unit)) { if (canMove) { canMove = unit == u || u.CanWalkOn(gameObject.tag); // You can walk here if it's to yourself or to a "walkable" unit. if (!canMove && isPusher) { if (isAvatarMover == false) { // If not a walkable, check if you are a 'Pusher' and it can be moved. BaseMover mover = u.GetComponent<BaseMover>(); if (mover != null) { canMove = mover.TryMove(xDir, zDir); } } else { if (currentAvatarUnit.Strength >= u.Weight) { // If not a walkable, check if you are a 'Pusher' and it can be moved. currentAvatarUnit._stateMachine.ChangeState((int)AvatarUnit.AvatarState.Pushing); //Starts push animation BaseMover mover = u.GetComponent<BaseMover>(); if (mover != null && mover.canBePushed) { canMove = mover.TryMove(xDir, zDir); } } } } } unit.OnCollided(u); u.OnCollided(unit); } return canMove && tile.CanWalkOn(unit); }
protected bool CanRotate(BaseTile tile, int xDir, int zDir) { bool canRotate = true; foreach (BaseUnit u in tile.OccupyingUnits(unit)) { if (canRotate) // A rotatable can't be pushed. canRotate = u == unit || u.transform.parent == transform || u.CanWalkOn(gameObject.tag); unit.OnCollided(u); u.OnCollided(unit); } return canRotate; }