Join Dan Violet Sagmiller for an in-depth discussion in this video Getting an image on the screen, part of Unity 5: 2D Generate Procedural Terrain.
- To get started, we're going to create a simple 2D Unity project, with a simple graphic, and make sure that it's saved. To get our project started, let's click a New Project. I'm going to rename the project Infinite Terrain. We could select 2D directly, as this is a 2D Unity course. However, you could stay with the 3D by default, except that some of the settings are going to be lost, and you'll have to switch them manually. And you'll also have to make sure you're using the correct axis, as some of the code and scripts really work best by using the correct axis as your up and down.
So, 2D, and then I'll create the project. If you want to find out more about creating 2D projects, as this is not intended to cover all of 2D graphics, I strongly recommend checking out the Unity 5 2D Essentials Training course with Jesse Freeman. So now we have our basic project started. It's empty, so we need to get a graphic into this. Something to keep in mind when you're trying to get graphics for your video game, is you can't just go around and download any graphic image that you want off the internet. There's a lot of copyright issues, expenses, what can be used for them.
So, if you do want to get free images, I recommend looking for things with CC0, or public domain. CC0 and public domain effectively mean that someone has decided to release their images, their graphics, their 3D models, or music out to the public for anyone to use without any reservation to who gets to use it, for what, and who gets paid for it. It's all free to go. So it's a great resource to check for. So naturally, I went to a place that releases a lot of their content as CC0, or public domain.
Particularly, I chose OpenGameArt.org. There's a lot of graphics that you can find on here. A lot of people have released stuff as public domain or CC0. You can see here in the Licenses that it specifies Public Domain, or CC0 when you're searching for images. Not all of them have it, so be sure to check for it. This file, this secret_floor.jpg happens to be the graphic we'll be using for this. You can also find it in secret_floor.jpg under ExerciseFiles, Resources, Files 1.
Now to get this into the project, we're simply going to drag this file, secret_floor, into our Assets folder. Now Unity has this asset. However, most assets are also stored in a folder for the type of asset that this is. So I'm going to create a folder called Textures, and then drag secret_floor into Textures. So now I'm inside of the Textures folder. I have my secret_floor, and to get it inside of the scene, I'll simply drag it into the scene view.
Now most game objects, when they're dragged into the scene view, do not get a perfect 0, 0 Position. I recommend setting that manually. This helps with alignment later on in the game, with a lot of scripts, to help get rid of decimal places when they're not wanted. Unless you have a specific location that you want your graphic to show up, other than 0, 0, 0, I recommend starting all your graphics at 0, 0, 0. So let's play this and see if it works. And it does. We can see in the game that we have the graphics.
So I'm going to stop this now. And the last thing that we need to do is save the scene, so that we don't lose any of our work. I'll do that by going to File, Save Scene. Now we have our Textures folder. And under the Textures folder, is where we have our textures. We want to have a folder specifically for scenes. So let's create a New Folder, called Scenes. I'll go into the Scenes folder, and now I'm going to save the scene as Infinite Terrain.
And Save. Now you've seen how easy it is to get a simply 2D Unity project started, and add a graphic to it.
- Tiling images
- Controlling randomization and noise
- Moving and redrawing maps
- Creating smooth tile connections
- Animating terrain
- Adding a building layer
- Adding cities
- Making buildings
- Generating multi-part structures
- Saving and loading terrain