Skip to content

Instantly share code, notes, and snippets.

@TheAllenChou
Last active May 30, 2018 15:59
Show Gist options
  • Save TheAllenChou/257434c60689bdddc191fcdc43a1f531 to your computer and use it in GitHub Desktop.
Save TheAllenChou/257434c60689bdddc191fcdc43a1f531 to your computer and use it in GitHub Desktop.
int lastUpdateSector = 0;
void Update()
{
xRotation = Mathf.Repeat(xRotation, 360.0f);
int currentSector = (int) (xRotation / 45.0f);
if (currentSector != lastUpdate)
{
int n = lastUpdateSector - currentSector;
n = (n >= 0) ? n : -n;
if (n > 4)
n -= 4;
for (int i = 0; i < n; ++i)
{
// do your stuff
}
if (n > 0)
{
lastUpdateSector = currentSector;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment