2D Roguelike 3 of 14 : Tile Prefabs


In this video for our scavengers project we’re going to look at creating the additional pieces of the game board, including the floor, food pickups, obstacles and exit. The floor pieces are going to be the simplest, they’re just going to consist of a sprite, which is going to serve as the background for our level. Let’s go ahead and create a new game object. We’ll call this Floor1. And we’re going to add a sprite renderer component. For the sprite we’re going to choose our first floor sprite. We’re going to set the sorting layer for this to Floor. With that done we’re going to drag our floor tile to our Prefabs folder. And then we’re going to reuse this by switching the sprite to the next sprite in our sheet. This will be Floor2. Change it to Floor3. And then we’re just going to repeat the process. I’m going to fast forward the video while I do this. And there we go. Next we’re going to create the Exit tile. We can reuse this, change the name to Exit. And select our ExitSign sprite. The exit is going to need a box collider 2D component so that we can detect when the player has moved on to it. We’re going to set the box collider 2D to Is Trigger so that it won’t actually prevent the player from moving on to the space but just detect the collision. We’re going to set Exit to our Items layer so that it will be rendered under the Player but in front of the Floor. The only other thing we’re going to change is we’re going to change the tag to our Exit tag that we defined earlier. Drag that down to our Prefabs folder. Next we’re going to create our Food object. Select our Fruits sprite. We’re going to change the sorting layer to our items layer and we’re going to change the tag to Food. Now food is also going to use a box collider 2D with Is Trigger active. We’re going to make our Soda object next. And we’re going to change the tag to our predefined Soda tag. The layer can remain as default, because these are not actually going to block the player or enemies from moving in to their space they’re just going to be picked up if the player moves over them. Drag that down to the Prefabs folder. Next we’re going to create our Inner and Outer wall tiles. Let’s do the outer walls first. Call this OuterWall1. And we’ll select our Rocky wall sprite here. This is going to have a box collider 2D but it’s not going to be a trigger, this is actually going to prevent the player and the enemies from moving in to it’s space. We’re going to set the tag to Untagged. And the layer to Blocking Layer, because this is actually going to block the player’s movement. The sorting layer can be Floor, because this is going to be part of the outer wall, which is going to border the level which nothing is going to be able to move in to. Drag it to the Prefabs folder. And we can reuse this for OuterWall2. Rename it to OuterWall2 and let’s change the sprite. Now to be clear, these are only visual variations. We don’t want all of our tiles to look the same, which is why we’re creating these. And we’ll do OuterWall3 as well. Next we’re going to create the InnerWalls, which are going to block the player and enemies from moving around the level. We’ll change the name here to Wall1 and we’re going to change the sprite as well. We’ll use our first bramble sprite. Now this is actually going to be placed on top of the floor so we’re going to set the sorting layer to Items. And it’s also going to block movement so we’re going to keep it on blocking layer. Let’s drag it down. And now we’re just going to create a few variations. on the same thing. Make Wall2. Change the sprite, drag it down. And so there we go, we’ve basically got our complete tile set, there’s going to be a couple of modified versions of these wall tiles that we’ll fit in later, but this is basically everything that we need to move to the next stage, which is laying our our game board using a script. Subtitles by the Amara.org community

33 thoughts on “2D Roguelike 3 of 14 : Tile Prefabs

  1. Quick tip to save time and keystrokes when creating the floor and wall prefabs….

    Create the first prefab the same way as demonstrated in the video and drag it to the Prefabs folder. Now you'll have a prefab named "Floor1" for example. With the prefab highlighted press (CTRL + D) to duplicate it. The duplicate will be named"Floor2". You can keep doing it and it will keep adding one to each new prefab. If you have a bunch of prefabs named this way like "Floor1"…."Floor99", you can duplicate any of them and the resulting prefab will be named "Floor100".

    I'm not a big fan of changing file suffixes using the click-pause-click-pause-click-backspace-type method so I thought this was a nice touch by the Unity team.

  2. Isn't this like the most inefficient way of making a tile system? I mean, that's basicly wasting resources while you could just make the board use one material, one mesh filter and one renderer. And scripting a procedural mesh is not that hard as it seems.

  3. …This is definitely one of those tutorials where you're going to have a really tough time if you don't have access to multiple screens.

  4. I'm having an odd problem… I want to import and use an SDK with this tutorial but the assets I import from it replace the layers with new layers compatible with it instead. Unfortunately the layers were already established before the tutorial…

    You'd think you'd include making the layers in the tutorial if adding other projects could mess with the layers.

  5. Slow down, zoom in to show what you're doing, explain things more. This isn't my favorite Unity tutorial video….

  6. This tutorial is really pretty poor. It focuses on all of the trivial things while omitting fundamentals that people actually want to know about. Yes, it's aimed at an "intermediate" level, but if that's the case, why are you spending time explicitly making copies of things, as if someone with "intermediate" experience wouldn't know how to do that? Explanations of how/why you set up the layers/tags the way you did would have really been appreciated.

  7. Maybe it's just me, but as someone who's only been using Unity for about a week.
    The whole piece by piece floor prefab thing strikes me as being oddly inefficient and outdated compared to how you guys tend to do things in Unity, maybe there isn't a better way to do it, it just feels like there should be given how good Unity usually is about making things easier/faster to do.

  8. This tutorial is so useless, i did everything this guy asked me too and suddenly my "exit" prefab has the sprite of the soda, the floors are sometimes identic etc, so i go ahead and try to delete some of them and BOOM my whole Prefab folder is gone and i can't undo it Thank you Unity gr8 Tutorial!

  9. The whole tutorial I was expecting something like "This is the wrong way to do it, from now on just press this button and the engine will do it for you"

  10. 2:42 really threw me off for a minute. He says "We're gonna change the sorting layer to Items", but it was already on items from the Exit prefab. Yet when he opens the dropdown, Floor is ticked. What the hell?

  11. I don't get the difference between not assigning something to "is trigger" and to assigning the layer to "blocking Layer"? wouldn't assigning any of these without the other make the player not able to move through that game object? please answer Thanks In advance 🙂

  12. For some reason, whenever I render the scene all of the tiles that have a hitbox won't appear. Not sure if it´s a thing on the code on part 4 or the way I created the tile prefabs using this tutorial…

  13. @Unity : Can't we just duplicate the prefab and change the sprite ? Drag + Alt to make a copy then change the sprite ?

  14. Following the steps here screwed me up for a long time. I'm using the 2017.1.0f3 version of Unity and when following the steps as done in the video it kept changing the wrong prefab. It took me until after writing the enemy script step and testing it out to find out that one of my floor tile prefabs had a tag of exit and causing my character to freeze. Reselect the item in the hierarchy before editing stuff in the inspector or it will screw you up too.

  15. It seems like there has to be a better way to handle this? Wouldn't it be more efficient/easier to create an empty tile and then use a script to pick a random tile and assign it a floor tile sprite?

  16. Lifehack for those who knows how to change tag/layer and etc.

    Just copy and paste all needed prefabs from Complete-Game folder .

  17. Got so carried away with making floor prefabs, that I made a floor prefab out of all the sprites. 10/10 would make floor prefabs again.

  18. I wrote a C# script to skip the whole repeat process of creating the same objects over and over with different sprites. Its a really simple class that has nothing but a private sprite array that you can use to hold all the sprites. Then on the Start method, use Random to randomly apply one of the sprites.

Leave a Reply

Your email address will not be published. Required fields are marked *