-
Notifications
You must be signed in to change notification settings - Fork 5
/
Test.cs
77 lines (59 loc) · 1.75 KB
/
Test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using UnityEngine;
namespace Section.Classes.Structs
{
public struct Item2 // VALUE TYPE -- Stack
{
public string name;
public int itemID;
public Item2(string name, int itemID)
{
this.name = name;
this.itemID = itemID;
}
}
public class Item // REFERENCE TYPE -- Heap
{
public string name;
public int itemID;
public Item(string name, int itemID)
{
this.name = name;
this.itemID = itemID;
}
}
public class Test : MonoBehaviour
{
Item sword;
Item hammer = new Item("Hammer", 2);
Item2 bread;
private void Start()
{
sword = new Item("Sword", 1);
bread.name = "Bread";
bread.itemID = 3;
Debug.Log("Class: Reference Type");
Debug.Log("Weapon to upgrade: " + hammer.name);
ChangeValue(hammer);
Debug.Log("Upgraded weapon: " + hammer.name);
Debug.Log("Struct: Value Type");
Debug.Log("Food to upgrade: " + bread.name);
ChangeValue(bread);
Debug.Log("Upgraded food: " + bread.name);
// Notes for later
int age = 31; // value type
// move value types
// bool, bytes, char, doubles, float, int, long, structs
string myName = "Sarah"; // reference type
// more reference types
// strings, arrays, delegates
}
void ChangeValue(Item2 structItem) // value type
{
structItem.name = "Bread Loaf";
}
void ChangeValue(Item classItem) // reference type
{
classItem.name = "War Hammer";
}
}
}