MiniGame Mods
MiniGame Modifications to Integrate Inventory System
Modify PlayerController.cs by updating code in OnTriggerEnter that reflects changes needed to integrate the inventory system with player collisions with collectible and hazard game objects. The Hazard.cs script was included with the InventorySystem Package.
Note: GameData.cs was included in the updated Scripts for InventorySystem, it had logic to clear the inventory each time the startButton was clicked in the MiniGame using the MiniGameManager.cs script from Project 1. The logic in GameData has been commented out. See second code block below
/// <summary>
/// THIS IS THE EVENT that starts the chain reaction of events
/// </summary>
/// <param name="collision">Collision.</param>
//Customize to your game needs
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Collectible"))
{
//update score
PickUp collectibleItem = collision.GetComponent<PickUp>();
GameData.instanceRef.Add(collectibleItem.Value); //points for each specific item's value
//ADD THIS NEW CODE FOR INVENTORY SYSTEM
GameData.instanceRef.AddItem(collectibleItem.itemInstance); //points for each specific item's value
Debug.Log("Hit collectible");
Destroy(collision.gameObject);
}
else if (collision.CompareTag("Hazard"))
{
//decrease health
//what type of object has tag "Hazard"
//ADD THIS NEW CODE FOR INVENTORY SYSTEM - HAZARD COMPONENT
Hazard hazardItem = collision.GetComponent<Hazard>();
if (hazardItem != null)
{
GameData.instanceRef.TakeDamage(hazardItem.Value);
}
else
{
Debug.Log("Collided with a different type Hazard");
//TODO add code for Hazard-type items
PickUp item = collision.GetComponent<PickUp>();
GameData.instanceRef.TakeDamage(item.Value);
}
Destroy(collision.gameObject);
}
else
{
Debug.Log("Hit Something Else");
}
} //end function
Update Spawned Prefabs:
Items with tag: Hazard must have the PickUp script removed, they must have the Hazard.cs script attached.
Items with tag: Collectible must have the updated PickUp script. This requires that the Prefab be modified by attaching a ScriptableObject for the ItemInstance: Item, as in the image below. So, create ScriptableObjects that correspond with your custom Concrete custom class, then add those items to your Collectible Prefabs. See Video below for steps

Updated GameData.cs - 4/13/20
No longer clears the inventory when ResetGameData( ) is executed.
//to restart entire game
public void ResetGameData()
{
health = 100; //initialize
score = 0;
experience = 0;
// inventory.inventory.Clear();
miniGameWinner = false;
}
Last updated
Was this helpful?