diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index cc2a0b75..2d4cbc3a 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -2770,7 +2770,6 @@ MonoBehaviour: m_EditorClassIdentifier: _timeMultiplier: 2000 _startHour: 12 - _timeText: {fileID: 2089282903} _sunLight: {fileID: 705507994} _sunriseHour: 7 _sunsetHour: 20.5 @@ -2839,6 +2838,7 @@ GameObject: - component: {fileID: 329780515} - component: {fileID: 329780514} - component: {fileID: 329780513} + - component: {fileID: 329780517} m_Layer: 5 m_Name: Canvas m_TagString: Untagged @@ -2931,6 +2931,22 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 0} +--- !u!114 &329780517 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 329780512} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2649ed9748ff3864880311f1c2aecdef, type: 3} + m_Name: + m_EditorClassIdentifier: + _dateTimeController: {fileID: 307039699} + _playerController: {fileID: 858145505} + _timeText: {fileID: 2089282903} + _moneyText: {fileID: 443940496} --- !u!1 &353014637 GameObject: m_ObjectHideFlags: 0 @@ -3152,7 +3168,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: New Text + m_text: Money m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -7466,7 +7482,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: New Text + m_text: TimeText m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} diff --git a/Assets/Scripts/Actions/Eat.cs b/Assets/Scripts/Actions/Eat.cs index 863e54e2..1e4efff4 100644 --- a/Assets/Scripts/Actions/Eat.cs +++ b/Assets/Scripts/Actions/Eat.cs @@ -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); } } } diff --git a/Assets/Scripts/DateTimeController.cs b/Assets/Scripts/DateTimeController.cs index fcb9a501..f2762ead 100644 --- a/Assets/Scripts/DateTimeController.cs +++ b/Assets/Scripts/DateTimeController.cs @@ -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() diff --git a/Assets/Scripts/GameUIController.cs b/Assets/Scripts/GameUIController.cs new file mode 100644 index 00000000..d524d6cd --- /dev/null +++ b/Assets/Scripts/GameUIController.cs @@ -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"); + } + } +} diff --git a/Assets/Scripts/GameUIController.cs.meta b/Assets/Scripts/GameUIController.cs.meta new file mode 100644 index 00000000..3f7fbd2f --- /dev/null +++ b/Assets/Scripts/GameUIController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2649ed9748ff3864880311f1c2aecdef +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 3d1e45d3..18264c4e 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -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);