-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBossTargetSliderController.cs
More file actions
78 lines (69 loc) · 2.6 KB
/
BossTargetSliderController.cs
File metadata and controls
78 lines (69 loc) · 2.6 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BossTargetSliderController : MonoBehaviour
{
private BossController bc;
// Start is called before the first frame update
public LevelController levelController;
public Slider bossTargetSlider;
public GameObject markerPrefab;
public BossPhaseJSON[] bossPlan;
public int hitCount = 2;
public float[] targets;
public float maxTarget;
void Start()
{
//Obtain boss controller for hit count
bc = GameObject.FindGameObjectWithTag("Boss").GetComponent<BossController>();
//Fill up target array
bossPlan = levelController.bossPlan;
for (int i = 0; i < bossPlan.Length; i++)
{
if (bossPlan[i].untilHits == -1) continue; //if -1, skip it
targets[i] = bossPlan[i].untilHits;
}
RectTransform slidedRT = gameObject.GetComponent<RectTransform>();
float maxLen = slidedRT.rect.width;
maxTarget = targets[targets.Length - 1]; //We assume last value in the JSON is the largest value. BAD IMPLEMENTATION
bossTargetSlider.maxValue = maxTarget; //max Value is last value of target
//For each target, place target at i
foreach (float i in targets)
{
float distanceInBar = ((i / maxTarget) * maxLen) - maxLen/2f;
RectTransform markerRT = Instantiate(markerPrefab).GetComponent<RectTransform>();
if (i == maxTarget)
{
Image markerI = markerRT.GetComponent<Image>();
markerI.color = Color.yellow;
}
markerRT.SetParent(bossTargetSlider.transform);
markerRT.localPosition = new Vector2(distanceInBar, -15f);
markerRT.localScale = new Vector2(0.15f, 0.15f);
}
StartCoroutine("checkFinalTarget");
StartCoroutine("checkHitCount");
}
// Update is called once per frame
void Update()
{
//bossTargetSlider.value = hitCount;
}
IEnumerator checkHitCount()
{
while (hitCount < maxTarget)
{
hitCount = bc.HitCount;
bossTargetSlider.value = hitCount;
yield return new WaitUntil(() => bc.HitCount != hitCount);
}
}
IEnumerator checkFinalTarget()
{
yield return new WaitUntil(() => bossTargetSlider.value == maxTarget);
ColorBlock cb = bossTargetSlider.colors;
cb.normalColor = Color.yellow;
bossTargetSlider.colors = cb;
}
}