Game Development Reference
In-Depth Information
Creating inventory items
Like with conversation items we created in Chapter 4 , The Game World , we want to be
able to simply manage items that can be used or bought in our game.
First, we need a scriptable object to describe our inventory items. So, create a new script
in Assets\Scripts\Classes named InventoryItem and populate it with the
following structure:
using UnityEngine;
public class InventoryItem : ScriptableObject
{
public Sprite Sprite;
public Vector3 Scale;
public string ItemName;
public int Cost;
public int Strength;
public int Defense;
}
Note
Note that we haven't implemented all of the properties we described earlier, just a subset
as an example. You can add more if you wish.
Now that we have our scriptable object, we need an editor script to create our inventory
items. So, create another script in Assets\Scripts\Editor named Invent-
oryItemAssetCreator and populate it with the following structure (note that we are
again using our generic utility class to make this very easy to implement):
using UnityEngine;
using UnityEditor;
public class InventoryItemAssetCreator : MonoBehaviour {
[MenuItem("Assets/Create/Inventory Item")]
public static void CreateAsset()
{
Search WWH ::




Custom Search