I have a loop and need a loop line having a range of values ββfrom 0 to 1 and back to 0.

So, I am currently using this code
public class DayNightCycle : MonoBehaviour
{
private float currentTime = 0;
private float secondsPerDay = 120;
private Image cycleBar;
private void Start()
{
cycleBar = GetComponent<Image>();
UpdateCycleBar();
}
private void Update()
{
currentTime += Time.deltaTime;
if (currentTime >= secondsPerDay)
currentTime = 0;
UpdateCycleBar();
}
private void UpdateCycleBar()
{
cycleBar.rectTransform.localScale = new Vector3(currentTime / secondsPerDay, 1, 1);
}
}
but now I need the behavior mentioned above. How to increase currentTimefrom 0 to 1, and then return to 0?
Problem: my loop line should increase left to right.
The night should last 40% of the maximum time, the remaining 20%.
source
share