58 lines
1.4 KiB
C#
58 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public TMP_Text usernameTxt;
|
|
public TMP_Text[] coinsTxt;
|
|
public TMP_Text[] gemsTxt;
|
|
public TMP_Text metalTxt;
|
|
public TMP_Text oxygenTxt;
|
|
public TMP_Text levelTxt;
|
|
public Slider levelSlider;
|
|
void Start()
|
|
{
|
|
GameManagerInstance.gameManager = this;
|
|
|
|
|
|
//Go back to login if not logged
|
|
if(!DBmanager.LoggedIn){
|
|
SceneManager.LoadScene(0);
|
|
}else{
|
|
usernameTxt.text = DBmanager.username;
|
|
RefreshData();
|
|
}
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public void RefreshData(){
|
|
foreach(TMP_Text txt in coinsTxt){
|
|
txt.text = DBmanager.Coins.ToString();
|
|
}
|
|
foreach(TMP_Text txt in gemsTxt){
|
|
txt.text = DBmanager.Gems.ToString();
|
|
}
|
|
metalTxt.text = DBmanager.Metal.ToString();
|
|
oxygenTxt.text = DBmanager.Oxygen.ToString();
|
|
levelTxt.text = Mathf.CeilToInt(DBmanager.Level).ToString();
|
|
|
|
float levelExcess = DBmanager.Level - Mathf.FloorToInt(DBmanager.Level);
|
|
levelSlider.value = Mathf.Clamp(levelExcess, 0.1f,1);
|
|
}
|
|
}
|
|
|
|
public static class GameManagerInstance{
|
|
public static GameManager gameManager;
|
|
}
|