added Game UI Controller

Show money on UI, buy items
This commit is contained in:
Vladimir Koshevarov
2022-10-18 16:55:38 +03:00
parent 32cdf47d4a
commit fc8393b29f
6 changed files with 78 additions and 17 deletions
+7 -4
View File
@@ -2,14 +2,17 @@
{
public class Eat : BaseAction
{
private int energyPerTick;
public Eat(int duration, int energyPerTick, double cost) : base(duration)
private double _price;
private int _energyPerTick;
public Eat(int duration, int energyPerTick, double price) : base(duration)
{
this.energyPerTick = energyPerTick;
_price = price;
_energyPerTick = energyPerTick;
}
public override void ApplyAction(PlayerController playerController)
{
playerController.foodEnergy.increase(energyPerTick);
playerController.foodEnergy.increase(_energyPerTick);
playerController.money.deduct(_price);
}
}
}
+3 -9
View File
@@ -1,5 +1,4 @@
using System;
using TMPro;
using UnityEngine;
public class DateTimeController : MonoBehaviour
@@ -10,9 +9,6 @@ public class DateTimeController : MonoBehaviour
[SerializeField]
private float _startHour;
[SerializeField]
private TextMeshProUGUI _timeText;
[SerializeField]
private Light _sunLight;
@@ -43,6 +39,9 @@ public class DateTimeController : MonoBehaviour
private TimeSpan _sunsetTime;
private DateTime _currentTime;
public DateTime CurrentTime => _currentTime;
// Start is called before the first frame update
void Start()
{
@@ -61,11 +60,6 @@ public class DateTimeController : MonoBehaviour
private void UpdateTime()
{
_currentTime = _currentTime.AddSeconds(Time.deltaTime * _timeMultiplier);
if (_timeText != null)
{
_timeText.text = _currentTime.ToString("HH:mm");
}
}
private void RotateSun()
+37
View File
@@ -0,0 +1,37 @@
using TMPro;
using UnityEngine;
public class GameUIController : MonoBehaviour
{
[SerializeField]
private DateTimeController _dateTimeController;
[SerializeField]
private PlayerController _playerController;
[SerializeField]
private TextMeshProUGUI _timeText;
[SerializeField]
private TextMeshProUGUI _moneyText;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
_moneyText.text = $"Money: {_playerController.money.Value}$";
UpdateTime();
}
private void UpdateTime()
{
if (_timeText != null)
{
_timeText.text = _dateTimeController.CurrentTime.ToString("HH:mm");
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2649ed9748ff3864880311f1c2aecdef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+1 -1
View File
@@ -3,7 +3,7 @@ using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Stat money = new Stat("Money", 1000.00);
public Stat money = new Stat("Money", 100.00);
public Stat rentAccount = new Stat("Rent Account", 0);
public Stat foodEnergy = new Stat("Food Energy", 0);
public Stat restEnergy = new Stat("Rest Energy", 0);