-
Notifications
You must be signed in to change notification settings - Fork 0
/
PickUp.cs
56 lines (46 loc) · 1.36 KB
/
PickUp.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickUp : MonoBehaviour {
Animator anim;
Inventory invScript;
public bool money;
public int moneyAmount;
Currency moneyScript;
public bool item;
public GameObject itemIcon;
bool pickedUp = false;
// Use this for initialization
void Start () {
anim = GameObject.FindWithTag("Player").GetComponent<Animator>();
moneyScript = GameObject.FindWithTag("GameController").GetComponent<Currency>();
invScript = GameObject.FindWithTag("GameController").GetComponent<Inventory>();
}
// Update is called once per frame
void OnTriggerStay(Collider player) {
if (player.tag == "Player")
{
if (Input.GetKeyDown(KeyCode.E) && !pickedUp)
{
pickedUp = true;
StartCoroutine("PlayAnim");
}
}
}
IEnumerator PlayAnim()
{
anim.SetTrigger("pickup");
yield return new WaitForSeconds(1);
if (money)
{
moneyScript.gold += moneyAmount;
Destroy(gameObject);
}
else if (item)
{
GameObject i = Instantiate(itemIcon);
i.transform.SetParent(invScript.invTab.transform);
Destroy(gameObject);
}
}
}