-
Notifications
You must be signed in to change notification settings - Fork 0
/
WarningScript.cs
89 lines (82 loc) · 2.45 KB
/
WarningScript.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
88
89
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class WarningScript : MonoBehaviour
{
public int? index = null;
public int? previndex = null;
public int maxIndex = 1;
public GameObject MusicPlayer;
public bool reservesoundtime = false;
public TextMeshProUGUI TextBox;
// Start is called before the first frame update
// Update is called once per frame
public bool? Warning(string text)
{
previndex = index;
gameObject.SetActive(true);
TextBox.text = text;
previndex = index;
if(Input.GetKeyDown("a") || Input.GetKeyDown(KeyCode.LeftArrow)){
if(index == null){
index = maxIndex+1;
}
if(index >= 0){
index--;
if(index < 0){
index = maxIndex;
}
}
}
if(Input.GetKeyDown("d") || Input.GetKeyDown(KeyCode.RightArrow)){
if(index == null){
index = -1;
}
if(index <= maxIndex){
index++;
if(index > maxIndex){
index = 0;
}
}
}
if(index != null){
int result = AnimationController();
if(result != -1){
gameObject.SetActive(false);
return 1==result;
}
else{
return null;
}
}
else{
return null;
}
}
public void Sound(AudioClip soundclip){
if(!reservesoundtime){
MusicPlayer.GetComponent<MusicPlayer>().PlayMusic(soundclip);
}
else{
reservesoundtime = false;
}
}
int AnimationController(){
if(previndex != index && previndex != null && index != null){
gameObject.transform.GetChild((int)previndex).GetComponent<Animator>().SetBool("selected",false);
}
Animator indexAnim = gameObject.transform.GetChild((int)index).GetComponent<Animator>();
indexAnim.SetBool ("selected", true);
if(Input.GetKey(KeyCode.Space)){
reservesoundtime = false;
indexAnim.SetBool ("pressed", true);
}
else if(indexAnim.GetBool("pressed")){
indexAnim.SetBool ("pressed", false);
reservesoundtime = true;
return (int)index;
}
return -1;
}
}