/// <summary> /// Update is called every frame, if the MonoBehaviour is enabled. /// </summary> void Update() { Vector3 offset = -(new Vector3(position.x - Mathf.Floor(position.x), position.y - Mathf.Floor(position.y), 0)); for (int y = 0; y < pixels; ++y) { for (int x = 0; x < pixels; ++x) { var pixel = this[x, y]; Vector3 tileOffset = offset; Tile tile = tileType(gridToMap(new Vector2(x, y))); pixel.GetChild(0).gameObject.SetActive(tile == Tile.Water); pixel.GetChild(1).gameObject.SetActive(tile == Tile.Ground); if (tile == Tile.Water) { tileOffset += waves.WaveOffset(gridToMap(new Vector2(x, y))); } else if (tile == Tile.Ground) { tileOffset.z += .25f; } Position(pixel, new Vector3(x, y, 0), tileOffset); if (gridToMap(new Vector2(x, y)) == Vector2.zero) { pixel.gameObject.SetActive(false); } else { pixel.gameObject.SetActive(true); } } } { Vector2 pos = mapToGrid(boat.mapPos); var bt = boat.transform; var boatOffset = offset + waves.WaveOffset(boat.mapPos); Position(bt, pos, boatOffset); if (boat.mapPos.x - position.x > allowedOffset) { position.x = boat.mapPos.x - allowedOffset; } else if (boat.mapPos.x - position.x < -allowedOffset) { position.x = boat.mapPos.x + allowedOffset; } if (boat.mapPos.y - position.y > allowedOffset) { position.y = boat.mapPos.y - allowedOffset; } else if (boat.mapPos.y - position.y < -allowedOffset) { position.y = boat.mapPos.y + allowedOffset; } } }