-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerManager.cs
99 lines (93 loc) · 2.37 KB
/
PlayerManager.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
public class PlayerManager : MonoBehaviour
{
[SerializeField] GameObject[] characters;
private int playerIndex;
[SerializeField] Color[] PlayerColors;
[SerializeField] MeshRenderer playerMesh;
[SerializeField] Material playerMat;
[SerializeField] GameObject homeUI;
[SerializeField] GameObject buyCharacterUI;
[SerializeField] GameObject[] charactersPanel;
[SerializeField] GameObject[] lockUI;
[SerializeField] int[] characterPrice;
[SerializeField] Text[] characterPriceText;
// Start is called before the first frame update
void Start()
{
if(PlayerPrefs.HasKey("PlayerIndex"))
{
playerIndex = PlayerPrefs.GetInt("PlayerIndex");
OnCharacterSelect(playerIndex);
playerMesh.enabled = false;
}
else
{
playerMesh.enabled = true;
playerMat.color = playerMesh.material.color;
}
for (int i = 0; i < characterPriceText.Length; i++)
{
characterPriceText[i].text = characterPrice[i].ToString();
}
OnlockUI();
}
void OnlockUI()
{
for(int i = 0; i < lockUI.Length; i++)
{
if(PlayerPrefs.HasKey("PlayerBought" + i))
{
lockUI[i].SetActive(false);
}
}
}
public void BuyCharacter(int index)
{
if (!PlayerPrefs.HasKey("PlayerBought" + index))
{
bool success = CoinManager.instance.UseCoin(characterPrice[index]);
if (!success)
return;
PlayerPrefs.SetInt("PlayerBought" + index, 1);
OnCharacterSelect(index);
homeUI.SetActive(true);
buyCharacterUI.SetActive(false);
}
OnlockUI();
}
public void OnCharacterSelect(int index)
{
if (PlayerPrefs.HasKey("PlayerBought" + index))
{
PlayerPrefs.SetInt("PlayerIndex", index);
playerMesh.material.color = PlayerColors[index];
playerMat.color = PlayerColors[index];
playerMesh.enabled = false;
for (int i = 0; i < characters.Length; i++)
{
if (i == index)
characters[i].SetActive(true);
else
characters[i].SetActive(false);
}
}
else
{
homeUI.SetActive(false);
buyCharacterUI.SetActive(true);
for (int i = 0; i < charactersPanel.Length; i++)
{
if (i == index)
charactersPanel[i].SetActive(true);
else
charactersPanel[i].SetActive(false);
}
}
}
}