loops - On every third iteration C# -
this question has answer here:
- how can every nth item list<t>? 8 answers
i have loop performing simple task me every time variable multiple of 3, have create big loop contains every multiple of 3 logical or (3, 6, 9, ...). wondering if there more efficient way of doing this.
this code snippet:
if (wavecounter == 3 || wavecounter == 6 || wavecounter == 9 || wavecounter == 12) { amount = 0.03f; daynight.lightamout = amount; daynight.light.intensity = mathf.lerp(daynight.light.intensity, daynight.lightamout, fadetime * time.deltatime); } else { amount = 1f; daynight.lightamout = amount; daynight.light.intensity = mathf.lerp(daynight.light.intensity, daynight.lightamout, fadetime * time.deltatime); }
my objective here rid of writing multiples of 3 in if statement , still achieving same goal every time wavecounter variable next multiple of 3.
if((wavecounter % 3) == 0)
modulo arithmetic: divides number 3 , checks remainder. number divisable 3 has no remainder (and ==0
)
Comments
Post a Comment