neon_run/Assets/Scripts/BlockProgressBar.cs
2025-11-24 09:36:52 +05:30

39 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlockProgressBar : MonoBehaviour
{
[Range(0f, 1f)]
public float progress = 0f;
public int blockCount;
private float previousProgress = -1f;
void Update()
{
// Only apply effect when progress changes
if (progress != previousProgress)
{
UpdateBlocks();
previousProgress = progress;
}
}
void UpdateBlocks()
{
// Calculate how many blocks should be enabled based on progress
int enabledBlockCount = Mathf.RoundToInt(progress * blockCount);
// Clamp to valid range
enabledBlockCount = Mathf.Clamp(enabledBlockCount, 0, blockCount);
// Enable/disable child objects
for (int i = 0; i < transform.childCount; i++)
{
bool shouldBeActive = i < enabledBlockCount;
transform.GetChild(i).gameObject.SetActive(shouldBeActive);
}
}
}