forked from JXPorter/OkitaUnity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.cs
More file actions
102 lines (96 loc) · 1.95 KB
/
Example.cs
File metadata and controls
102 lines (96 loc) · 1.95 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
class Zombie
{
public int damage = 10;
public static Zombie operator +(Zombie a, Zombie b)
{
Zombie z = new Zombie();
int powerUp = a.damage + b.damage;
z.damage = powerUp;
return z;
}
public static bool operator <(Zombie a, Zombie b)
{
if (a.damage < b.damage)
{
return true;
} else
{
return false;
}
}
public static bool operator >(Zombie a, Zombie b)
{
if (a.damage > b.damage)
{
return true;
} else
{
return false;
}
}
}
class Supplies
{
public int bandages;
public int ammunition;
public float weight;
public Supplies(int size)
{
bandages = size;
ammunition = size * 2;
weight = bandages * 0.2f + ammunition * 0.7f;
}
public static Supplies operator +(Supplies a, Supplies b)
{
Supplies s = new Supplies(0);
int sBandanges = a.bandages + b.bandages;
int sAmmunition = a.ammunition + b.ammunition;
float sWeight = a.weight + b.weight;
s.bandages = sBandanges;
s.ammunition = sAmmunition;
s.weight = sWeight;
return s;
}
public static Supplies operator *(Supplies a, int b)
{
Supplies s = new Supplies(0);
int sBandages = a.bandages * b;
int sAmmunition = a.ammunition * b;
float sWeight = a.weight * b;
s.bandages = sBandages;
s.ammunition = sAmmunition;
s.weight = sWeight;
return s;
}
}
void Start()
{
Zombie a = new Zombie();
Zombie b = new Zombie();
Debug.Log(a.damage);
Debug.Log(b.damage);
Zombie c = a + b;
Debug.Log(c.damage);
Supplies supplyA = new Supplies(3);
Supplies supplyB = new Supplies(9);
Supplies combinedAB = supplyA + supplyB;
Debug.Log(combinedAB.weight);
Supplies sm = new Supplies(5);
Debug.Log(sm.weight);
sm = sm * 3;
Debug.Log(sm.weight);
a.damage = 9;
if (a < b)
{
Debug.Log("a has less damage!");
}
}
// Update is called once per frame
void Update()
{
}
}