GameData, PickUp Mods
These are the modifications included in the Inventory System Package
The following scripts contain updated code that is already integrated the Inventory System Unity Package.
IMPORTANT: You may get a compile error in your code when importing the InventorySystem Package due to inconsistencies between using the GameData variable: score, sometimes the variable totalScore was used with the same meaning. Fix the error: I recommend using score / Score, instead of totalScore/TotalScore, because it is what is used in subsequent code for Project 3 - LevelManager.cs
The error above may show up in PlayerStats.cs: Make the following change
private void UpdateDisplay()
{
scoreText.text = "Score: " + GameData.instanceRef.Score; //replace .TotalScore
healthText.text = "Health: " + GameData.instanceRef.Health;
}Class Pickup
updated Apr 10,2019
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//combines frontEnd UI and BackEnd
public class PickUp : MonoBehaviour {
public ItemInstance itemInstance;
private int value;
//read-only property
public int Value
{
get { return value; }
}
private void Start()
{
this.value = itemInstance.item.value;
}
/// <summary>
/// Adds the item to GameData Inventory
/// Can be executed by button.onClick
/// when added as a listener
/// </summary>
public void AddItem( ) //can be called onClick for a button
{
GameData.instanceRef.AddItem(this.itemInstance);
}
}//end class PickUpGameData Changes:
Updated Class GameData with CustomEvent and Inventory, AddItem(ItemInstance), BoostHealth( ), BoostExperience( )
IMPORTANT: You may get a compile error in your code due to inconsistencies between using the GameData variable: score, sometimes the variable totalScore was used with the same meaning. Fix the error: I recommend using score / Score, instead of totalScore/TotalScore, because it is what is used in subsequent code for Project 3 - LevelManager.cs
GameData: Final Version
updated Apr 3,2020
Last updated
Was this helpful?