public void Move(int direction) { if (isDead) { // no zombies plz return; } t = 0; int x = (int)transform.position.x; int y = (int)transform.position.y; anim.SetTrigger("Walk"); switch (direction) { case TileClass.NORTH: y++; break; case TileClass.EAST: transform.localScale = new Vector3(1, 1, 1); x++; break; case TileClass.SOUTH: y--; break; case TileClass.WEST: transform.localScale = new Vector3(-1, 1, 1); x--; break; } // Reset the tiles to current position TileClass tc = gameboard.GetTileAtCoordinate(transform.position.x, transform.position.y).GetComponent <TileClass>(); if (tc != null) { currentTile = tc; nextTile = tc; } GameObject obj = gameboard.GetTileAtCoordinate(transform.position.x, transform.position.y); TileClass tempCurrentTile = null; if (obj != null) { tempCurrentTile = obj.GetComponent <TileClass>(); } obj = gameboard.GetTileAtCoordinate(x, y); TileClass tempNextTile = null; if (obj != null) { tempNextTile = obj.GetComponent <TileClass>(); } if (tempCurrentTile != null && !tempCurrentTile.HasWall(direction) && tempNextTile != null && !tempNextTile.HasEntity()) { currentTile = tempCurrentTile; nextTile = tempNextTile; currentTile.entity = null; nextTile.entity = gameObject; // Set order in layer renderer.sortingOrder = (int)nextTile.transform.position.y * -2; } }