Chapter 3. Working with Assets
In the last chapter, we designed our game and created our game environment, the virtual world that our players will interact with during the game. Now, we are ready to start populating our game environment with more than just trees and water.
In this chapter, we will take a close look at importing Unity and third-party assets from Unity's Asset Store directly into our game. These assets will be used to make our game environment more enjoyable for users. We'll add our pig, piglet, baby chick, adult chicken, old farmer, and Colt, our young farmer. These are our game's characters.
We'll import barns for the two farmers. We'll also create our own 3D asset using free software and import it into our game.
After reading this chapter, you will:
Understand what a Unity asset is
Be able to import a Unity asset into your game
Be able to import a third-party asset into your game
Understand Unity packages
Be able to import a Unity package into your game
Be able to use Blender to...
Assets are defined as useful or valuable things. In Unity, assets are useable game objects. There are three basic types of assets: Unity, user-created, and third party. As the names suggest, they are based on how the asset is created. Unity comes with free assets and offers a library of premium (not free) assets. User-created assets are those that you create yourself. We will create our own assets later in this chapter. The final asset type is third party, which indicates that someone other than you or Unity created it.
When we select the Assets drop-down menu, we see several functions available to us. The functions we'll cover in this chapter are Create, Import New Asset…, and Import Package, as shown in the following screenshot:
Navigating to Assets | Create reveals several types of assets we can create directly from within Unity. You'll notice that assets can be scripts, shaders, prefabs, materials, animations, and more. Assets are essentially any item we use in our game. We'll use...
In the last chapter, we imported an asset package so that we could create and modify our game's terrain. In this section, we'll look at what these packages are and how we'll use them in Unity and for our game.
Asset packages are bundles of assets grouped together. We can create packages to share our assets with others or to save them for use in another game or Unity application. We can even create asset bundles to sell in Unity's Asset Store.
To create an asset package, you simply select all the assets you want in the package, using the Project view. Then you have two options. Your first option is to right-click and select Export Package. The second option is to navigate to Assets | Export Package. Both options result in the same outcome.
In addition to the ability to export packages from Unity, we can also import asset packages into Unity. To import an asset package, we simply navigate to Assets | Import Package menu option:
When importing asset packages, we can select from one...
Unity operates a store called the Unity Asset Store. There are a great number of assets available to Unity developers. The store is accessible directly on the Web at http://assetstore.unity3d.com. You can also open a window within Unity to display the Asset Store. This is accomplished by navigating to Window | Asset Store.
Regardless of how you connect to the Unity Asset Store, you'll see a hierarchical category listing in the top-right corner of the store:
Clicking on the triangular icons to the left of each category reveals subcategories. Some categories have multiple subcategories, which helps you find what you are looking for quickly.
When you click on a category, its contents will be viewable. Clicking on a specific asset will display several characteristics of that asset. These characteristics include:
Title
Publisher
Rating
Price
Purchase button or, in the case of free assets, an "Open in Unity" button
Version of Unity required
Description
Package contents
File size
Version number...
Adding assets to your game
Let's add some assets to our Little Farmer Colt game. First, we'll visit the Unity Asset Store, select an asset, inspect it, download it, and add it to our game. Next, we'll import a custom asset package.
Using the Unity Asset Store
The following steps illustrate how to find an asset from the Unity Asset Store and add it to our game. We'll look at specific characteristics of the asset, so you know what to look at when using the store.
Launch Unity and open your project. Remember, we named our project LittleFarmerColt
.
Open your scene by navigating to File | Open Scene menu selection. This will bring up a Load Scene file dialog box with your project's Assets
folder displayed. The name of my scene is FarmScene. Double-click on the scene file to open it. Alternatively, single-click on the scene file and click on the Open button, as shown in the following screenshot:
Now we are ready to open the Unity Asset Store. We will search for an object appropriate for our game.
From...
Using Blender to create assets for your game
We previously discussed the ability for us to create assets outside of Unity, export them into a format compatible with Unity, and then import them into our game. In this section, we'll do just that.
There are several tools that can be used to create 3D objects for use in Unity. One of the most commonly used is Blender. Blender is a free and open source 3D modeling program that has an impressive array of capabilities. There are several books and online tutorials that can teach you how to use Blender to create assets. Teaching you how to create them from scratch is beyond the scope of this book.
What we do have time to discuss is how to take a Blender object and export it into a Unity-supported format. Let's do that together by performing the following steps:
If you do not already have a copy of Blender on your computer, download a copy from http://www.blender.org.
Download the corn_stalk.blend
file from this book's web page.
Launch Blender.
In Blender...
In this chapter, we covered Unity assets and asset packages. You visited the Unity Asset Store and reviewed what information is available on assets located in the Store. You gained experience downloading and importing assets into your game. You also learned a little about how to create 3D objects using Blender, a free and open-source 3D modeling tool.
In the next chapter, you'll animate the game's characters. The animations will include idle animations for all characters, both human and animal, talk animations for the farmers. Colt, our player-controlled character, will also receive walk and take animations. The take animation will be for the harvesting of corn and water. And, just for fun, we'll give Colt the ability to jump.