-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial.cs
More file actions
83 lines (77 loc) · 2 KB
/
Tutorial.cs
File metadata and controls
83 lines (77 loc) · 2 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
79
80
81
82
83
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tutorial : MonoBehaviour
{
[SerializeField] GameObject[] popUps;
[SerializeField] float fadeTime;
private int popupIndex;
private float waitCounter;
private bool startCounting;
private void Awake()
{
foreach (var popup in popUps)
{
popup.SetActive(false);
}
}
private void Update()
{
if (!gameObject.activeInHierarchy) return;
CanvasGroup canvasGroup;
for (int i = 0; i < popUps.Length; i++)
{
if (i == popupIndex)
{
canvasGroup = popUps[i].GetComponent<CanvasGroup>();
popUps[i].SetActive(true);
if (canvasGroup.alpha <= 1)
canvasGroup.alpha += Time.deltaTime;
}
else
{
canvasGroup = popUps[i].GetComponent<CanvasGroup>();
if (canvasGroup.alpha >= 0)
canvasGroup.alpha -= Time.deltaTime;
else if (canvasGroup.alpha <= 0)
popUps[i].SetActive(false);
}
}
switch (popupIndex)
{
case 0:
if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.A))
{
waitCounter = 0;
startCounting = true;
}
if (startCounting && waitCounter < fadeTime)
waitCounter += Time.deltaTime;
else if (waitCounter >= fadeTime)
{
waitCounter = 0;
startCounting = false;
popupIndex++;
}
break;
case 1:
if (Input.GetKeyDown(KeyCode.LeftShift))
{
startCounting = true;
}
if (startCounting && waitCounter < fadeTime)
waitCounter += Time.deltaTime;
else if (waitCounter >= fadeTime)
{
waitCounter = 0;
startCounting = false;
popupIndex = -1;
}
break;
case 2:
if (Input.GetKeyDown(KeyCode.Space))
popupIndex = -1;
break;
}
}
}