/
PickupUIController.cs
87 lines (76 loc) · 2.49 KB
/
PickupUIController.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
87
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Displays the X/X numbers when a pickup item is being carried.
/// </summary>
public class PickupUIController : MonoBehaviour {
public Canvas textCanvas;
public Text topNumber;
public Text middleBar;
public Text bottomNumber;
public Transform pickupTransform;
GameObject mainCamera;
PickupController pickupController;
void Start ()
{
mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
pickupController = this.transform.parent.GetComponent<PickupController>();
setTextOpacity(0);
}
void Update ()
{
//place canvas above pickup and point at camera
//Vector3 pickupPosition = pickupTransform.position;
//pickupPosition.x = 0;
//Vector3 UIposition = new Vector3(0, pickupPosition.z * -1/2, pickupPosition.x * -1/2);
//this.transform.position = UIposition;
this.transform.LookAt(mainCamera.transform);
if (!pickupController)
{
setTextOpacity(0);
}
}
public void setTopText(float newText, byte opacity)
{
Color textColour = new Color32(50, 50, 50, 255);
setTopText(newText, opacity, textColour);
}
public void setTopText(float newText, byte opacity, Color32 textColour)
{
topNumber.text = newText.ToString();
setTextColor(textColour);
setTextOpacity(opacity);
//todo: check if toptext > bottomtext, if so use large toptext size, otherwise use normal size
}
public void setBottomText(float newText, byte opacity)
{
Color textColour = new Color32(50, 50, 50, 255);
setBottomText(newText, opacity, textColour);
}
public void setBottomText(float newText, byte opacity, Color32 textColour)
{
bottomNumber.text = newText.ToString();
setTextColor(textColour);
setTextOpacity(opacity);
}
void setTextOpacity(byte opacity)
{
Color32 newcolor = topNumber.color;
newcolor.a = opacity;
topNumber.color = newcolor;
newcolor = middleBar.color;
newcolor.a = opacity;
middleBar.color = newcolor;
newcolor = bottomNumber.color;
newcolor.a = opacity;
bottomNumber.color = newcolor;
}
void setTextColor(Color newColour)
{
topNumber.color = newColour;
middleBar.color = newColour;
bottomNumber.color = newColour;
}
}