//-------------------- // add given 'pickup' objects to our Dictionary public void Add(PickUp pickup) { // get the type of this pickup object PickUp.PickUpType type = pickup.type; // init total to zerpo int oldTotal = 0; // IF we can find this type in the Dictionary // then set 'oldTotal' to the associated value if (items.TryGetValue(type, out oldTotal)) { // add 1 to existing total (since we just picked one up) items[type] = oldTotal + 1; } else { // if we could not find the type key in the Dictionary // then add new item, with total 1 (since we just picked one up) items.Add(type, 1); } // tell the display object to update the UI display with the new totals in 'items' Dictionary playerInventoryDisplay.OnChangeInventory(items); }
void OnTriggerEnter2D(Collider2D hit) { if (hit.CompareTag("Pickup")) { Pickup item = hit.GetComponent <Pickup> (); inventory.Add(item); playerInventoryDisplay.OnChangeInventory(inventory); Destroy(hit.gameObject); } }
// Use this for initialization void Start() { playerInventoryDisplay = GetComponent <PlayerInventoryDisplay>(); playerInventoryDisplay.OnChangeInventory(items); //인벤토리 초기값 설정 inventory_c.position = new Vector3(658.45f, 46.25f, 0); //아이템 이미지 체크x item_gun.gameObject.SetActive(false); item_key.gameObject.SetActive(false); item_pet.gameObject.SetActive(false); }
public void Add(PickUp pickup) { PickUp.PickUpType type = pickup.type; int oldTotal = 0; if (items.TryGetValue(type, out oldTotal)) { items[type] = oldTotal + 1; } else { items.Add(type, 1); } playerInventoryDisplay.OnChangeInventory(items); }
//---------------------- // actions for when parent GameObject (Player) has hit a 2D collider inside another object void OnTriggerEnter2D(Collider2D hit) { // IF we hit something taqgged 'Pickup' if (hit.CompareTag("Pickup")) { // THEN do the following: // - get reference to PickUp object inside the hit Gameobject PickUp item = hit.GetComponent <PickUp>(); // add this PickUp item to our List 'inventory' inventory.Add(item); // update the display of inventory contents to the user UI playerInventoryDisplay.OnChangeInventory(inventory); // destroy the hit GameObject Destroy(hit.gameObject); } }
void Start() { playerInventoryDisplay = GetComponent<PlayerInventoryDisplay>(); playerInventoryDisplay.OnChangeInventory(inventory); }
// Use this for initialization void Start() { playerInventoryDisplay = GetComponent <PlayerInventoryDisplay>(); playerInventoryDisplay.OnChangeInventory(items); }
void Start() { playerInventoryDisplay.OnChangeInventory(inventory); }
private void Start() { // Updates the inventory _playerInventoryDisplay.OnChangeInventory(Items); }