-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChallengesListUI.cs
65 lines (51 loc) · 2.17 KB
/
ChallengesListUI.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class ChallengesListUI : MonoBehaviour
{
[SerializeField] ChallengeItemUI challengePrefab;
ChallengeList challengeList;
// Start is called before the first frame update
void Start()
{
challengeList = GameObject.FindGameObjectWithTag("Player").GetComponent<ChallengeList>();
challengeList.onUpdate += Redraw;
Redraw();
}
private void Redraw()
{
//transform.DetachChildren();
foreach (ChallengeStatus status in challengeList.GetStatuses())
{
ChallengeItemUI uiInstance = Instantiate<ChallengeItemUI>(challengePrefab, transform);
float tempFloat = uiInstance.transform.position.y;
//int numberOfClassObjects = FindObjectsOfType(typeof(ChallengeItemUI)).Length;
GameObject[] tempChallengeObject = GameObject.FindGameObjectsWithTag("Challenge");
if(tempChallengeObject.Length > 1)
{
// Checks to see if there are 3 challenges present then turns all the additional ones off
if(tempChallengeObject.Length > 3)
{
for (int i = 0; i < tempChallengeObject.Length; i++)
{
tempChallengeObject[3].SetActive(false);
}
}
// Assigns the location of the challenges
for(int i = 1; i < tempChallengeObject.Length; i++)
{
tempChallengeObject[i].transform.position = new Vector3(uiInstance.transform.position.x, tempFloat - 1.0f, uiInstance.transform.position.z);
tempFloat = tempChallengeObject[i].transform.position.y;
}
//uiInstance.transform.position = new Vector3(uiInstance.transform.position.x, uiInstance.transform.position.y - 1.0f, uiInstance.transform.position.z);
}
uiInstance.Setup(status);
}
}
// Update is called once per frame
void Update()
{
}
}