Game Development Reference
In-Depth Information
player.Magic = input.Magic;
player.Name = input.Name;
player.NoOfAttacks = input.NoOfAttacks;
player.Occupation = input.Occupation;
player.Position = input.Position;
player.Speed = input.Speed;
player.Strength = input.Strength;
player.Weapon = input.Weapon;
player.Inventory = new List<InventoryItem>();
foreach (var item in input.Inventory)
{
player.Inventory.Add(
(InventoryItem)Resources.Load("Inventory Items/" +
item));
}
return player;
}
This is pretty much the same in reverse, except for the inventory. We cannot simply create
a new inventory item because each InventoryItem is a ScriptableObject that
we created in our game in the editor.
So to give the player the correct InventoryItems from our game's library, we call
Resources.Load to pull the item from our game project, passing the path to In-
ventoryItem and its name (which we saved earlier). Then, we add them to the player's
inventory.
Hopefully, you can see why I stuck with the previous model to give you a more in-depth
look at how to manage ScriptableObjects with serialization.
Search WWH ::




Custom Search