EventSystems
How do I use Event Systems
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
39 | string level = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name; | 1 |
File name: LevelController.cs
Copy
38 public void LevelSelect(){
39 string level = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name;
40
41 switch(level){
42 case "Level 1":
43 if(GameController.instance != null){
44 GameController.instance.currentLevel = 1;
45 }
46 break;
47
48 case "Level 2":
49 if(GameController.instance != null){
50 GameController.instance.currentLevel = 2;
51 }
52 break;
53
54 case "Level 3":
55 if(GameController.instance != null){
56 GameController.instance.currentLevel = 3;
57 }
58 break;
59
60 case "Level 4":
61 if(GameController.instance != null){
62 GameController.instance.currentLevel = 4;
63 }
64 break;
65
66 case "Level 5":
67 if(GameController.instance != null){
68 GameController.instance.currentLevel = 5;
69 }
70 break;
71
72 case "Level 6":
73 if(GameController.instance != null){
74 GameController.instance.currentLevel = 6;
75 }
76 break;
77
78 case "Level 7":
79 if(GameController.instance != null){
80 GameController.instance.currentLevel = 7;
81 }
82 break;
83
84 case "Level 8":
85 if(GameController.instance != null){
86 GameController.instance.currentLevel = 8;
87 }
88 break;
89
90 case "Level 9":
91 if(GameController.instance != null){
92 GameController.instance.currentLevel = 9;
93 }
94 break;
95
96 case "Level 10":
97 if(GameController.instance != null){
98 GameController.instance.currentLevel = 10;
99 }
100 break;
101
102 case "Level 11":
103 if(GameController.instance != null){
104 GameController.instance.currentLevel = 11;
105 }
106 break;
107
108 case "Level 12":
109 if(GameController.instance != null){
110 GameController.instance.currentLevel = 12;
111 }
112 break;
113
114 case "Level 13":
115 if(GameController.instance != null){
116 GameController.instance.currentLevel = 13;
117 }
118 break;
119
120 case "Level 14":
121 if(GameController.instance != null){
122 GameController.instance.currentLevel = 14;
123 }
124 break;
125
126 case "Level 15":
127 if(GameController.instance != null){
128 GameController.instance.currentLevel = 15;
129 }
130 break;
131
132 }
133
134 SceneManager.LoadScene (level);
135
136 }
EventSystems 119 lượt xem
Gõ tìm kiếm nhanh...