/
Veteread
/
Packer
Обзор
Документация
Войти
/
Veteread
/
Packer
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
GameProgressTracker.cs
72 строки
2 KB
Veteread
upload files
04 май 2025, 10:49
04 май 2025, 10:49
a5dcff3
Код
Авторство
О чём код?
using UnityEngine; using UnityEngine.UI; public class GameProgressTracker : MonoBehaviour { [SerializeField] private Collider2D playArea; [SerializeField] private Image progressBar; [SerializeField] private GameObject finishButton; [SerializeField][Range(0, 1)] private float completionThreshold = 0.7f; public void CheckCompletion() { if (playArea == null) { Debug.LogError("PlayArea not assigned!"); return; } Bounds bounds = playArea.bounds; Collider2D[] colliders = Physics2D.OverlapAreaAll(bounds.min, bounds.max); float totalArea = bounds.size.x * bounds.size.y; float filledArea = 0f; foreach (var collider in colliders) { if (collider != null && collider.CompareTag("Block")) { if (collider is BoxCollider2D box) { filledArea += box.size.x * box.size.y; } } } float percentage = Mathf.Clamp01(filledArea / totalArea); UpdateProgressUI(percentage); } private void UpdateProgressUI(float percentage) { if (progressBar != null) { progressBar.fillAmount = percentage; } if (finishButton != null) { finishButton.SetActive(percentage >= completionThreshold); } } private float CalculateFilledPercentage() { Bounds bounds = playArea.bounds; float totalArea = bounds.size.x * bounds.size.y; float filledArea = 0f; Collider2D[] colliders = Physics2D.OverlapAreaAll(bounds.min, bounds.max); foreach (var collider in colliders) { if (collider.CompareTag("Block") && collider != playArea) { if (collider is BoxCollider2D box) { filledArea += box.size.x * box.size.y; } } } return Mathf.Clamp01(filledArea / totalArea); } }