Creating the Tile Prefabs
Проверено с версией:: 5
This is part 3 of 14 of the 2D Roguelike tutorial in which we create the tile prefabs for the floor, wall, food, soda and exit prefabs.
Creating the Tile Prefabs
Средняя 2D Roguelike tutorial
- 00:02 - 00:04
In this video for our scavengers project
- 00:04 - 00:06
we're going to look at creating the additional
- 00:06 - 00:08
pieces of the game board, including the
- 00:08 - 00:12
floor, food pickups, obstacles and exit.
- 00:13 - 00:15
The floor pieces are going to be the simplest,
- 00:15 - 00:17
they're just going to consist of a sprite,
- 00:17 - 00:20
which is going to serve as the background for our level.
- 00:20 - 00:23
Let's go ahead and create a new game object.
- 00:24 - 00:26
We'll call this Floor1.
- 00:27 - 00:30
And we're going to add a sprite renderer component.
- 00:34 - 00:37
For the sprite we're going to choose
- 00:40 - 00:42
our first floor sprite.
- 00:45 - 00:47
We're going to set the sorting layer for this
- 00:47 - 00:49
- 00:49 - 00:53
With that done we're going to drag our floor tile
- 00:53 - 00:55
to our Prefabs folder.
- 00:56 - 01:00
And then we're going to reuse this by switching the sprite
- 01:00 - 01:02
to the next sprite in our sheet.
- 01:03 - 01:05
This will be Floor2.
- 01:12 - 01:14
Change it to Floor3.
- 01:16 - 01:18
And then we're just going to repeat the process.
- 01:18 - 01:21
I'm going to fast forward the video while I do this.
- 01:35 - 01:36
And there we go.
- 01:36 - 01:39
Next we're going to create the Exit tile.
- 01:39 - 01:43
We can reuse this, change the name to Exit.
- 01:44 - 01:47
And select our ExitSign sprite.
- 01:47 - 01:51
The exit is going to need a box collider 2D component
- 01:51 - 01:54
so that we can detect when the player has moved on to it.
- 02:00 - 02:02
We're going to set the box collider 2D
- 02:02 - 02:04
to Is Trigger so that it won't actually
- 02:04 - 02:06
prevent the player from moving on to the space
- 02:06 - 02:08
but just detect the collision.
- 02:08 - 02:11
We're going to set Exit to our Items layer
- 02:11 - 02:16
so that it will be rendered under the Player but in front of the Floor.
- 02:18 - 02:19
The only other thing we're going to change is
- 02:19 - 02:21
we're going to change the tag
- 02:22 - 02:25
to our Exit tag that we defined earlier.
- 02:27 - 02:29
Drag that down to our Prefabs folder.
- 02:30 - 02:33
Next we're going to create our Food object.
- 02:37 - 02:40
Select our Fruits sprite.
- 02:43 - 02:45
We're going to change the sorting layer
- 02:45 - 02:49
to our items layer and we're going to change the tag to Food.
- 02:49 - 02:53
Now food is also going to use a box collider 2D
- 02:53 - 02:55
with Is Trigger active.
- 03:00 - 03:02
We're going to make our Soda object next.
- 03:04 - 03:06
And we're going to change the tag
- 03:06 - 03:09
to our predefined Soda tag.
- 03:09 - 03:11
The layer can remain as default,
- 03:11 - 03:13
because these are not actually going to block
- 03:13 - 03:16
the player or enemies from moving in to their space
- 03:16 - 03:19
they're just going to be picked up if the player moves over them.
- 03:20 - 03:22
Drag that down to the Prefabs folder.
- 03:23 - 03:25
Next we're going to create our
- 03:25 - 03:28
Inner and Outer wall tiles.
- 03:30 - 03:32
Let's do the outer walls first.
- 03:32 - 03:34
Call this OuterWall1.
- 03:36 - 03:41
And we'll select our Rocky wall sprite here.
- 03:43 - 03:45
This is going to have a box collider 2D
- 03:45 - 03:47
but it's not going to be a trigger,
- 03:47 - 03:49
this is actually going to prevent the player and the enemies
- 03:49 - 03:51
from moving in to it's space.
- 03:52 - 03:55
We're going to set the tag to Untagged.
- 03:57 - 03:59
And the layer to Blocking Layer,
- 03:59 - 04:03
because this is actually going to block the player's movement.
- 04:03 - 04:06
The sorting layer can be Floor,
- 04:06 - 04:08
because this is going to be part of the outer wall,
- 04:08 - 04:10
which is going to border the level
- 04:10 - 04:12
which nothing is going to be able to move in to.
- 04:15 - 04:17
Drag it to the Prefabs folder.
- 04:19 - 04:21
And we can reuse this for OuterWall2.
- 04:21 - 04:24
Rename it to OuterWall2 and let's change the sprite.
- 04:29 - 04:33
Now to be clear, these are only visual variations.
- 04:33 - 04:35
We don't want all of our tiles to look the same,
- 04:35 - 04:37
which is why we're creating these.
- 04:39 - 04:41
And we'll do OuterWall3 as well.
- 04:44 - 04:46
Next we're going to create the InnerWalls,
- 04:46 - 04:49
which are going to block the player and enemies
- 04:49 - 04:51
from moving around the level.
- 04:53 - 04:55
We'll change the name here to Wall1
- 04:55 - 04:57
and we're going to change the sprite as well.
- 04:58 - 05:02
We'll use our first bramble sprite.
- 05:02 - 05:04
Now this is actually going to be placed on
- 05:04 - 05:07
top of the floor so we're going to set
- 05:07 - 05:10
the sorting layer to Items.
- 05:11 - 05:13
And it's also going to block movement so we're
- 05:13 - 05:15
going to keep it on blocking layer.
- 05:15 - 05:17
Let's drag it down.
- 05:18 - 05:20
And now we're just going to create a few variations.
- 05:20 - 05:22
on the same thing.
- 05:22 - 05:24
- 05:26 - 05:28
Change the sprite, drag it down.
- 06:00 - 06:02
And so there we go, we've basically got our
- 06:02 - 06:04
complete tile set, there's going to be a
- 06:04 - 06:06
couple of modified versions of these
- 06:06 - 06:08
wall tiles that we'll fit in later,
- 06:08 - 06:10
but this is basically everything that we need
- 06:10 - 06:13
to move to the next stage, which is laying
- 06:13 - 06:16
our our game board using a script.