-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pickable.cs
35 lines (31 loc) · 1.11 KB
/
Pickable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pickable : Interactable
{
[SerializeField] List<Item> items = new List<Item>();
AudioSource pickSfx;
private void Awake()
{
pickSfx = GetComponentInChildren<AudioSource>();
//Inactivate all objects stored in this game object
GameObject itemsObj = transform.Find("Items").gameObject;
}
protected override void Interact()
{
pickSfx.Play();
int numItems = transform.Find("Items").childCount;
Debug.Log($"number of items:{numItems}");
GameObject itemsObj = transform.Find("Items").gameObject;
for (int i = 0; i < numItems; i++)
{
items.Add(itemsObj.transform.GetComponentsInChildren<ItemPickup>()[i].GetItem());
}
Inventory inventory = GameObject.FindWithTag("Inventory").GetComponent<Inventory>();
inventory.AddItems(items);
// if (inventory.AddItem(item))
// Debug.Log("Item added to inventory");
// Debug.Log("Picking up " + item.name);
Destroy(gameObject);
}
}