-
Notifications
You must be signed in to change notification settings - Fork 5
/
SelectRandom.cs
34 lines (30 loc) · 974 Bytes
/
SelectRandom.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
using UnityEngine;
namespace Section.Arrays.Challenge02
{
public class SelectRandom : MonoBehaviour
{
/// Challenge Overview:
/// Create an array of 5 names
/// Create an array of 5 ages that correspond to each name
/// Create an array of 5 cars associates with each name
///
/// Randomly select a name and print all related details
///
/// Bonus: Handle print with the space key
///
public string[] names;
public int[] ages;
public string[] cars;
public int randomID;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
randomID = Random.Range(0, names.Length);
Debug.Log(randomID);
Debug.Log("Name: " + names[randomID] + " Age: " + ages[randomID] + " Vehicle: " + cars[randomID]);
}
}
}
}