More scoring.

This commit is contained in:
Khauvinkh
2024-08-18 18:55:24 +02:00
parent ded4de5cca
commit 9b4726113a
84 changed files with 13836 additions and 48 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class Scoreboard: MonoBehaviour
@@ -11,6 +12,8 @@ public class Scoreboard: MonoBehaviour
public float _timeLeft;
public bool _running;
public TextMeshPro textMesh;
public void Start()
{
@@ -19,17 +22,20 @@ public class Scoreboard: MonoBehaviour
Instance = this;
}
_running = true;
SetObjective(CurrentObjective);
UpdateText();
}
public void SetObjective(LevelObjective objective)
{
CurrentObjective = objective;
StagingManager.SetStage(objective.Stage);
ProductCounts = new();
_timeLeft = objective.TimeLimit;
_running = true;
}
public void ScoreProduct(Product product)
@@ -76,7 +82,8 @@ public class Scoreboard: MonoBehaviour
}
_timeLeft -= Time.deltaTime;
Debug.Log(_timeLeft);
UpdateText();
if (_timeLeft <= 0)
{
@@ -84,6 +91,25 @@ public class Scoreboard: MonoBehaviour
_running = false;
}
}
public void UpdateText()
{
string text = $"Time left: {Mathf.Floor(_timeLeft)}\n";
foreach (var quota in CurrentObjective.Quotas)
{
if (ProductCounts.ContainsKey(quota.Type))
{
text += $"{quota.Type.name}: {TotalCount(quota.Type)}/{quota.Quantity}\n";
}
else
{
text += $"{quota.Type.name}: 0/{quota.Quantity}\n";
}
}
textMesh.text = text;
}
public void CountScores()
{
@@ -91,6 +117,13 @@ public class Scoreboard: MonoBehaviour
foreach (var quota in CurrentObjective.Quotas)
{
if (!ProductCounts.ContainsKey(quota.Type))
{
success = false;
Debug.LogError($"Not enough {quota.Type.name}");
break;
}
if (quota.Quantity > TotalCount(quota.Type))
{
success = false;

View File

@@ -19,14 +19,12 @@ public class StagingManager: MonoBehaviour
Level2 = 2,
}
public void Start()
public void OnEnable()
{
if (Instance == null)
{
Instance = this;
}
SetStage(StageEnum.Level1);
}
public void OnDestroy()