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); }
//Used by the teleport of portal tiles protected void TeleportUnit(BaseUnit unit, BaseTile previousTile, BaseTile destinationTeleportTile) { if (previousTile == destinationTeleportTile || destinationTeleportTile == null)// Came from the other portal { return; } if (!destinationTeleportTile.CanWalkOn(unit)) { return; } BaseTile.TeleportTo(unit, this, destinationTeleportTile); if (unit is AvatarUnit) { AvatarUnit avatar = (AvatarUnit)unit; avatar.EmptyMoveQueue(); } }