I'm trying to simulate the sun temperature based on the day time. Assuming that at 12:00 it should be tempMax
and at 24:00 tempMin
how can I PingPong between the 2 values cyclically?
private void Update()
{
hoursText.text = "time: "+ hours.ToString("00");
daysText.text = "day: " + days.ToString();
tempText.text = temperature.ToString("00") + " °C";
if (hours < 24)
{
hours += Time.deltaTime ;
rotations.z = hours * 360 / 24;
}
if (hours >= 24)
{
hours = 0;
days += 1;
}
temperature = Mathf.PingPong(1/hours, tempMax) - tempMin;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…