-
Notifications
You must be signed in to change notification settings - Fork 5
/
MasterIf_04.cs
40 lines (35 loc) · 1.03 KB
/
MasterIf_04.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
using UnityEngine;
namespace Section.IfThen.Challenge05
{
public class MasterIf_04 : MonoBehaviour
{
/// Challenge Overview:
///
/// 01: Create a program that when the player presses the space key
/// the score value is incremented.
/// 02: When the score value is greater than 50
/// the cube turns Green.
///
/// Note: At the start of the program, set the cube color to red.
///
public GameObject cube;
public int score = 0;
// Start is called before the first frame update
void Start()
{
cube.GetComponent<Renderer>().material.color = Color.red;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && score <= 50)
{
score += 25;
}
if (score > 50)
{
cube.GetComponent<Renderer>().material.color = Color.green;
}
}
}
}