-
Notifications
You must be signed in to change notification settings - Fork 18
/
FarmManager.cs
93 lines (82 loc) · 2.23 KB
/
FarmManager.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FarmManager : MonoBehaviour
{
public PlantItem selectPlant;
public bool isPlanting = false;
public int money=100;
public Text moneyTxt;
public Color buyColor = Color.green;
public Color cancelColor = Color.red;
public bool isSelecting = false;
public int selectedTool=0;
// 1- water 2- Fertilizer 3- Buy plot
public Image[] buttonsImg;
public Sprite normalButton;
public Sprite selectedButton;
// Start is called before the first frame update
void Start()
{
moneyTxt.text = "$" + money;
}
public void SelectPlant(PlantItem newPlant)
{
if(selectPlant == newPlant)
{
CheckSelection();
}
else
{
CheckSelection();
selectPlant = newPlant;
selectPlant.btnImage.color = cancelColor;
selectPlant.btnTxt.text = "Cancel";
isPlanting = true;
}
}
public void SelectTool(int toolNumber)
{
if(toolNumber == selectedTool)
{
//deselect
CheckSelection();
}
else
{
//select tool number and check to see if anything was also selected
CheckSelection();
isSelecting = true;
selectedTool = toolNumber;
buttonsImg[toolNumber - 1].sprite = selectedButton;
}
}
void CheckSelection()
{
if (isPlanting)
{
isPlanting = false;
if (selectPlant != null)
{
selectPlant.btnImage.color = buyColor;
selectPlant.btnTxt.text = "Buy";
selectPlant = null;
}
}
if (isSelecting)
{
if (selectedTool > 0)
{
buttonsImg[selectedTool - 1].sprite = normalButton;
}
isSelecting = false;
selectedTool = 0;
}
}
public void Transaction(int value)
{
money += value;
moneyTxt.text = "$" + money;
}
}