-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inventory.cs
86 lines (69 loc) · 2.42 KB
/
Inventory.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Inventory : MonoBehaviour
{
[SerializeField] private Vector3 _pickPosition;
[SerializeField] private Vector3 _pickRotation;
private UIManager _uiManager;
private GameObject _hand;
public bool _canPickItem;
private GameObject _itemToPick;
private GameObject _pickedItem;
public bool _hasTorch = false;
public bool _itemClose = false;
// Start is called before the first frame update
void Start()
{
_uiManager = GameObject.Find("UIManager").GetComponent<UIManager>();
//_hand = GameObject.Find("hand.R");
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.F) && _canPickItem && _itemClose)
{
_hand = GameObject.Find("hand.R");
_itemToPick.transform.parent = _hand.transform;
_itemToPick.transform.localPosition = _pickPosition;
_itemToPick.transform.localEulerAngles = _pickRotation;
_itemToPick.GetComponent<Rigidbody>().isKinematic = true;
_pickedItem = _itemToPick;
_canPickItem = false;
_uiManager.HideUIToggle();
_hasTorch = true;
Debug.Log(_canPickItem);
} else if (Input.GetKeyDown(KeyCode.F) && !_canPickItem && _itemClose)
{
_pickedItem.transform.parent = null;
_pickedItem.GetComponent<Rigidbody>().isKinematic = false;
_canPickItem = true;
_uiManager.ShowUIToggle("Presser F pour ramasser la torche");
_hasTorch = false;
Debug.Log(_canPickItem);
}
}
private void OnTriggerEnter(Collider other)
{
// message take object
if (other.tag == "TorchPlayer")
{
_uiManager.ShowUIToggle("Presser F pour ramasser la torche");
_canPickItem = true;
_itemClose = true;
_itemToPick = other.gameObject;
Debug.Log(_canPickItem);
}
}
private void OnTriggerExit(Collider other)
{
// close message
if (other.tag == "TorchPlayer")
{
_canPickItem = false;
_itemClose = false;
_uiManager.HideUIToggle();
Debug.Log(_canPickItem);
}
}
}