changes made, it was working before now space click isnt detected
This commit is contained in:
45
Assets/Scripts/TimeAliveMoney.cs
Normal file
45
Assets/Scripts/TimeAliveMoney.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class TimeAliveMoney : MonoBehaviour
|
||||
{
|
||||
public float moneyPerSecond = 0.1f;
|
||||
public TMP_Text moneyText;
|
||||
public TMP_Text totalMoneyText;
|
||||
public Player player;
|
||||
private bool isAlive = true;
|
||||
private float timeAlive = 0f;
|
||||
private float totalMoneyEarned = 0f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
totalMoneyEarned = PlayerPrefs.GetFloat("Money", 0f);
|
||||
totalMoneyText.text = ((int)totalMoneyEarned).ToString() + "$";
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (player.gameStarted && isAlive == true) {
|
||||
timeAlive += Time.deltaTime;
|
||||
float earnedMoney = timeAlive * moneyPerSecond;
|
||||
if (moneyText != null)
|
||||
moneyText.SetText(((int)earnedMoney).ToString() + "$");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPlayerDeath()
|
||||
{
|
||||
isAlive = false;
|
||||
totalMoneyEarned += timeAlive * moneyPerSecond;
|
||||
SaveMoney();
|
||||
timeAlive = 0f;
|
||||
totalMoneyText.text = ((int)totalMoneyEarned).ToString() + "$";
|
||||
}
|
||||
|
||||
|
||||
private void SaveMoney()
|
||||
{
|
||||
PlayerPrefs.SetFloat("Money", totalMoneyEarned);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user