-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStoreMenu.cs
88 lines (74 loc) · 2.95 KB
/
StoreMenu.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
using UnityEngine;
using UnityEngine.UI;
public class StoreMenu : MonoBehaviour
{
public GameObject vehicleSelectedText;
public GameObject circleSelectedText;
int price;
private void Awake()
{
if (PlayerPrefs.GetInt("startMoneyGiven", 0) != 1)
{
PlayerPrefs.SetInt("coin", 300);
PlayerPrefs.SetInt("startMoneyGiven", 1);
}
}
public void GetPrice( int price)
{
this.price = price;
}
public void BuyVehicle(string tag)
{
if (PlayerPrefs.GetInt("SoundEnabled", 1) == 1)
{
FindObjectOfType<AudioManager>().Play("ButtonSound");
}
if (price < PlayerPrefs.GetInt("coin", 0))
{
PlayerPrefs.SetInt(tag + "IsBought", 1);
PlayerPrefs.SetInt("coin", PlayerPrefs.GetInt("coin", 0) - price);
GameObject.FindGameObjectWithTag(tag).GetComponent<Button>().interactable = true;
Destroy(GameObject.FindGameObjectWithTag(tag + "BuyButton"));
}
}
public void BuySize( string tag)
{
if (PlayerPrefs.GetInt("SoundEnabled", 1) == 1)
{
FindObjectOfType<AudioManager>().Play("ButtonSound");
}
if (PlayerPrefs.GetInt("circleSize", 10) * 10 <= PlayerPrefs.GetInt("coin", 0))
{
PlayerPrefs.SetInt("coin", PlayerPrefs.GetInt("coin", 0) - PlayerPrefs.GetInt("circleSize", 10) * 10);
PlayerPrefs.SetInt("circleSize", PlayerPrefs.GetInt("circleSize", 10) + 10);
}
if(PlayerPrefs.GetInt("circleSize", 10) >= 400)
{
Destroy(GameObject.FindGameObjectWithTag("CircleBuyButton"));
}
GameObject.FindGameObjectWithTag("CircleBuyButton").GetComponentInChildren<Text>().text = (PlayerPrefs.GetInt("circleSize", 10) * 10 ).ToString() ;
}
public void SelectVehicle( string tag)
{
if (PlayerPrefs.GetInt("SoundEnabled", 1) == 1)
{
FindObjectOfType<AudioManager>().Play("ButtonSound");
}
if( PlayerPrefs.GetInt(tag + "IsBought" , 0) == 1 || tag == "Tank")
{
vehicleSelectedText.transform.SetParent(GameObject.FindGameObjectWithTag(tag).transform);
PlayerPrefs.SetString("selectedVehicle", tag);
vehicleSelectedText.transform.position = GameObject.FindGameObjectWithTag(tag).transform.TransformPoint(Vector3.up * 60);
}
}
public void SelectCircle( string tag)
{
if (PlayerPrefs.GetInt("SoundEnabled", 1) == 1)
{
FindObjectOfType<AudioManager>().Play("ButtonSound");
}
circleSelectedText.transform.SetParent(GameObject.FindGameObjectWithTag(tag).transform);
PlayerPrefs.SetString("selectedCircle", tag);
circleSelectedText.transform.position = GameObject.FindGameObjectWithTag(tag).transform.TransformPoint(Vector3.up * 60);
}
}