-
Notifications
You must be signed in to change notification settings - Fork 5
/
SpeedCheck.cs
49 lines (41 loc) · 1.16 KB
/
SpeedCheck.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
using System.Collections;
using UnityEngine;
namespace Section.Loops.Challenge02
{
public class SpeedCheck : MonoBehaviour
{
/// Challenge Overview:
/// Create a program that meets the following:
/// increment the value of speed every second
/// when speed is greater than MaxSpeed
/// stop incrementing (Random between 60 and 120)
///
public int speed;
[SerializeField]
private int _maxSpeed;
// Start is called before the first frame update
void Start()
{
_maxSpeed = Random.Range(60, 120);
StartCoroutine(SpeedRoutine());
}
IEnumerator SpeedRoutine()
{
while (true)
{
yield return new WaitForSeconds(0.5f);
speed += 5;
if (speed > _maxSpeed)
{
break;
}
}
/// do while variant:
//do
//{
// speed += 5;
// yield return new WaitForSeconds(0.5f);
//} while (speed > maxSpeed);
}
}
}