-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItemPickUp.cs
74 lines (62 loc) · 2.32 KB
/
ItemPickUp.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Tamana
{
public class ItemPickUp : MonoBehaviour
{
public static bool isPlayerNearby { private set; get; }
public static GameObject UI_PickItem { private set; get; }
public float distanceFromPlayer { get { return (GM.playerPosition - transform.position).sqrMagnitude; } }
private WaitForSeconds waitingTime = new WaitForSeconds(0.33f);
private void Awake()
{
UI_PickItem = GM.FindWithTag("PickItem");
PickItemFitToScreen();
RaycastHit hit;
if (Physics.Raycast(transform.position, Vector3.down, out hit, 300.0f, LayerMask.GetMask("Scene")))
transform.position = hit.point + (Vector3.up * 0.25f);
}
private void Start()
{
StartCoroutine(CheckPlayerDistance());
if (UI_PickItem.activeInHierarchy)
UI_PickItem.SetActive(false);
}
private void Update()
{
if (distanceFromPlayer < 0.6f && LevelUP.statusReference == null)
{
UI_PickItem.SetActive(true);
isPlayerNearby = true;
if (Input.GetButtonDown("Circle"))
{
PlayerControl.PotionManager.PickUpPotion(gameObject);
isPlayerNearby = false;
}
}
else
{
isPlayerNearby = false;
UI_PickItem.SetActive(false);
}
}
private IEnumerator CheckPlayerDistance()
{
while(true)
{
if (distanceFromPlayer < 16 && LevelUP.statusReference == null)
enabled = true;
else enabled = false;
yield return waitingTime;
}
}
private void PickItemFitToScreen()
{
var rt = UI_PickItem.GetComponent<RectTransform>();
var posx = Screen.width * 0.0f - (rt.sizeDelta.x * 0.0f);
var posy = Screen.height * -0.5f + (rt.sizeDelta.y * 0.5f) + (Screen.height * 0.1f);
rt.localPosition = new Vector3(posx, posy, 0);
}
}
}