Search Unity

Creating a "tile"map from a texture.

Discussion in 'Scripting' started by Smuth, Jun 10, 2007.

  1. Smuth

    Smuth

    Joined:
    Nov 11, 2006
    Posts:
    16
    Has anybody tried using image data to create instances of prefabs? I was hoping to do a side scrolling game but it's difficult to work with tiles without any kind of grid snapping in Unity.

    What I was hoping to do was create an image and look at the colour value to decide what prefab I would create at the same position. I would also probably use the alpha to flip and flop the object as well.

    Any help would be greatly appreciated.

    Thanks
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I've done something similar to that, so yep, it's quite possible. Only thing in this case is, you're presumably going to have quite a few tiles, in which case working with colors is going to be really hard. Instead I'd recommend creating a level editor, and use that to save the level as a file, instead of messing with textures. It will be much more pleasant to use.

    --Eric
     
  3. Smuth

    Smuth

    Joined:
    Nov 11, 2006
    Posts:
    16
    That is good to hear. I've looked around for reading and writing data files but haven't had any luck or seen any examples. Could you give me a hint as to what to look for?

    Thanks. I'm obviously a total newb. Even if I was to use the texture to create files I don't know how to reference it etc. :(
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's one here. As for referencing textures, you use GetPixel, but like I said, an actual level editor would be better in this case. Even just a simple text file with letters corresponding to different tiles would be a good start, and simpler to deal with than pixels in textures.

    --Eric