Concrete Class: Food

Based on the video in Customization Steps, this section provides details of how to create your own custom type of items that can be used in the InventorySystem.

The video below shows how to import updated InventorySystem scripts and how to write code to create your own custom concrete class and scriptable objects as required for project 3.

Note, the video above shows that an additional step may be required when implementing the constructor for your custom concrete child class. Make sure to include setting instanceType in the child class constructor as shown below, this step may not have been included in all videos, as it was part of the updated code modification for InventorySystem version2 on 4/11/2020.

instanceType = foodType.ToString(); //make sure to add code similar to this in the constructor

You will create a concrete child class: In this example: Food:

//updated 4/11/2020

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum FoodType {  Cake, Cheese, Watermelon}

public class Food : Item
{
    public FoodType foodType;

    public Food() //constructor
    {
        itemType = ItemType.Food;
        instanceType = foodType.ToString();
    }

    public override void Use()
    {
        GameData.instanceRef.BoostHealth(this.value);

    }
} //end of class

Last updated