I have the following code which I call in my Update()
function:
void changeCapsulePosition()
{
int timer;
timer = (int)Time.time;
if(GUICounters.score >= 1)
{
Debug.Log(timer);
if(timer % 5 == 0 && hasChanged == false)
{
Vector3 tempPosition = capsule1.transform.position;
capsule1.transform.position = capsule2.transform.position;
capsule2.transform.position = tempPosition;
hasChanged = true;
}
hasChanged = false;
}
}
I would like my 2 objects to change position once after every 5 seconds but as it is, it switches back and forth the entire time the timer is on 5. I’m assuming this is because it is being called by Update
and is ran quite a few times and since I change the hasChanged
variable back to false, the condition will be true throughout the entire second.
Is there a way I can just get it to run once every 5 seconds?