This repository was archived by the owner on Feb 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathArrayLooping.cs
More file actions
63 lines (56 loc) · 1.46 KB
/
ArrayLooping.cs
File metadata and controls
63 lines (56 loc) · 1.46 KB
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
59
60
61
62
63
using UnityEngine;
namespace Section.Arrays.Presentations
{
[System.Serializable]
public class Item
{
public int itemID;
public string name;
public string description;
}
public class ArrayLooping : MonoBehaviour
{
public Item[] myItems;
// Start is called before the first frame update
void Start()
{
foreach (var item in myItems)
{
Debug.Log(item.name);
}
// check for id 7
foreach (var item in myItems)
{
if (item.itemID == 7)
{
Debug.Log("You have this item");
}
else
{
Debug.Log("You do not have this item");
}
}
// check for id 7
for (int i = 0; i < myItems.Length; i++)
{
if (myItems[i].itemID == 7)
{
Debug.Log("You have this item");
}
else
{
Debug.Log("You do not have this item");
}
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
int randomID = Random.Range(0, myItems.Length);
Debug.Log(myItems[randomID].name);
}
}
}
}