C#, extending a class and a tile based world

Hi,

I’m trying to improve my programming and i’m looking into setting up a class that generates a tile map. I got that far and i started thinking about having different kinds of tiles.
Dirt tiles, floor tiles, rock, etc etc. So I setup a BaseTile class and for each type of tile i’d create their own class and extend the BaseTile class. But then i started thinking about how i could generate the associated geometry that should go along with the class.

What do i do now? Setup a prefab for each class of tile and add the appropriate script to each tile? I’m more used to the Flash approach still and in my head i’m still all about var dirtTile:smile:irtTile = new DirtTile();

With the knowledge i have now, i think the way to tackle this is just with prefabs. Is this correct?

As for the bonus question: Is it possible to use the polymorphism approach in unity3d? If so, could you show me how.

I would only use inheritance for this if you have a clear idea of what benefits it will offer. I don’t know the context so I can’t really comment as to whether inheritance would be a good choice here, but my guess would be that a purely component-based approach might be more effective.

Yes, you can create a base class that inherits from Monobehaviour, and then derive your other classes from that base class.