-
Notifications
You must be signed in to change notification settings - Fork 2
/
MenuButton.cs
52 lines (42 loc) · 1.11 KB
/
MenuButton.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MenuButton : MonoBehaviour {
public int characterIndex;
public int shipCost;
public string shipName;
public Text shipCostText;
private bool bought = true;
// Use this for initialization
void Start () {
if (shipCost == 0)
return;
bought = PlayerPrefs.HasKey(shipName);
if (!bought)
{
shipCostText.text = shipCost.ToString();
}
else
{
shipCostText.text = "";
}
}
public void ChoosePlayer()
{
if (bought)
{
GameManager.gameManager.characterIndex = characterIndex;
FindObjectOfType<Menu>().LoadGame();
}
else if(GameManager.gameManager.points >= shipCost)
{
PlayerPrefs.SetString(shipName, shipName);
GameManager.gameManager.characterIndex = characterIndex;
GameManager.gameManager.points -= shipCost;
PlayerPrefs.SetInt("Points", GameManager.gameManager.points);
FindObjectOfType<Menu>().SetPointsText(GameManager.gameManager.points);
FindObjectOfType<Menu>().LoadGame();
}
}
}