-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFarmSlot.cs
155 lines (136 loc) · 3.46 KB
/
FarmSlot.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class FarmSlot : MonoBehaviour
{
int currentPlant = 0;
float plantTime = 0;
int currentStage = 0;
public float timeBetweenStages = 5f;
public Farm farm;
public Sprite[] plant1;
public Sprite[] plant2;
public Sprite[] plant3;
public Sprite emptySlot;
public Sprite dry;
public Sprite locked;
public bool isLocked = true;
SpriteRenderer sprite;
public int slotIndex;
float speed = 1;
bool isDry = false;
// Start is called before the first frame update
void Start()
{
sprite = GetComponent<SpriteRenderer>();
sprite.sprite = emptySlot;
updatePlant();
}
// Update is called once per frame
void Update()
{
if (!isDry)
{
if (currentPlant != 0 && currentStage < 3)
{
plantTime -= Time.deltaTime*speed;
if (plantTime < 0)
{
plantTime = timeBetweenStages;
currentStage++;
updatePlant();
}
}
}
}
private void OnMouseEnter()
{
farm.SetOverFarmSlot(slotIndex);
}
private void OnMouseDown()
{
if(currentStage == 3)
{
farm.AddMoney(currentPlant * 20);
currentStage = 0;
currentPlant = 0;
updatePlant();
speed = 1;
}
}
private void OnMouseExit()
{
farm.SetOverFarmSlot(-1);
}
public void Plant(int plantId)
{
if (isLocked)
{
if (plantId == 6 && farm.money >= 100)
{
isLocked = false;
updatePlant();
farm.AddMoney(-100);
}
}
else if (plantId < 4 && currentPlant==0)
{
if (farm.money >= plantId * 10) {
isDry = true;
plantTime = timeBetweenStages;
currentPlant = plantId;
updatePlant();
farm.AddMoney(plantId * -10);
}
}
else if(plantId == 4)
{
Water();
}
else if (plantId == 5 && (farm.money>= 5) && (currentPlant != 0) && (currentStage < 3))
{
Fertilize();
}
}
public void updatePlant() {
if (isLocked)
{
sprite.sprite = locked;
}
else if (!isDry)
{
switch (currentPlant)
{
case 0:
sprite.sprite = emptySlot;
break;
case 1:
sprite.sprite = plant1[currentStage];
break;
case 2:
sprite.sprite = plant2[currentStage];
break;
case 3:
sprite.sprite = plant3[currentStage];
break;
}
} else
{
sprite.sprite = dry;
}
}
void Water()
{
if (currentPlant>0)
{
isDry = false;
updatePlant();
}
}
void Fertilize()
{
farm.AddMoney(-5);
speed *= 1.2f;
}
}