-
Notifications
You must be signed in to change notification settings - Fork 5
/
MasterSwitch_02.cs
58 lines (50 loc) · 1.54 KB
/
MasterSwitch_02.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
using UnityEngine;
namespace Section.Switch.Challenge02
{
public class MasterSwitch_02 : MonoBehaviour
{
/// Challenge Overview:
/// Create a program that changes the color of a GameObject based on key press
/// (1 : blue, 2 : red, 3 : green, 4 : black)
public GameObject cube;
private int _nextColor;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
_nextColor = 0;
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
_nextColor = 1;
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
_nextColor = 2;
}
if (Input.GetKeyDown(KeyCode.Alpha4))
{
_nextColor = 3;
}
switch (_nextColor)
{
case 0:
cube.GetComponent<Renderer>().material.color = Color.blue;
break;
case 1:
cube.GetComponent<Renderer>().material.color = Color.red;
break;
case 2:
cube.GetComponent<Renderer>().material.color = Color.green;
break;
case 3:
cube.GetComponent<Renderer>().material.color = Color.black;
break;
default:
Debug.Log("Invald Selection");
break;
}
}
}
}