To display multiple inventory icons for multiple pickups of the same type of object, follow these steps:
- Start with a new copy of the Simple2Dgame_SpaceGirl mini-game.
- Create a C# script class called PlayerInventory in the _Scripts folder:
using UnityEngine; public class PlayerInventory : MonoBehaviour { private PlayerInventoryDisplay playerInventoryDisplay; private int totalStars = 0; void Awake() { playerInventoryDisplay = GetComponent<PlayerInventoryDisplay>
(); } void Start() { playerInventoryDisplay.OnChangeStarTotal(totalStars); } void OnTriggerEnter2D(Collider2D hit) { if (hit.CompareTag("Star")) { totalStars++; playerInventoryDisplay.OnChangeCarryingStar(totalStars); Destroy(hit.gameObject); } } }
- Select the star GameObject in the Hierarchy window and make three more copies of it. There...