/// <summary> /// Function that can change the type of the tile and replace its self in the grid array /// </summary> /// <param name="newType">New Type to switch to</param> /// <param name="originalTile">The Tile to switch from</param> /// <returns>Reference to the new Tile</returns> public static BaseTile ChangeTo(Tile.TileTypes newType, BaseTile originalTile) { BaseTile newTile = null; switch (newType) { case TileTypes.Tile: newTile = originalTile.gameObject.AddComponent <Tile>(); break; case TileTypes.Satalite: newTile = originalTile.gameObject.AddComponent <Satellite>(); break; case TileTypes.CombineSatellite: newTile = originalTile.gameObject.AddComponent <CombineSatellite>(); break; case TileTypes.LightOutput: newTile = originalTile.gameObject.AddComponent <LightOutput>(); break; case TileTypes.LightTarget: newTile = originalTile.gameObject.AddComponent <TargetTile>(); break; case TileTypes.Asteroid: newTile = originalTile.gameObject.AddComponent <AsteroidTile>(); break; case TileTypes.LightTrigger: newTile = originalTile.gameObject.AddComponent <LightTrigger>(); break; case TileTypes.LightGate: newTile = originalTile.gameObject.AddComponent <LightGate>(); break; case TileTypes.SatelliteSplitter: newTile = originalTile.gameObject.AddComponent <SplitterSatellite>(); break; case TileTypes.LightFilter: newTile = originalTile.gameObject.AddComponent <FilterTile>(); break; } if (newTile == null) { //report an Error and Back out Debug.LogError("Could not Change Tile target"); return(null); } originalTile.RemoveTile(); newTile.AssignNewTile(originalTile.arrayPosition, originalTile.creator, Color.black); //Tile will sort its self out DestroyImmediate(originalTile); return(newTile); }