- Home /
 
Mathf.Repeat question...
When Using Mathf.Repeat and Time.deltaTime to constantly loop a variable, is there a way to easily keep track of how many times said variable has been looped (I have tried things like "if(Looping_Value==x)Loop_Count+=1" but it does not work out)? What am I doing wrong? Thanks
 function Update(){
     var Looping_Value : float = Mathf.Repeat(Looping_Value + (Time.deltaTime), 100);
     var Loop_Count : int;
 }
 
              Answer by numberkruncher · May 14, 2013 at 12:27 AM
Yes, you can calculate the number of times looped by maintaining the value of loopingValue and then simply dividing by your "frame" size of 100.
 var loopingValue:float;
 var wrappedValue:float;
 var loopCount:int;
 function Update() {
     loopingValue += Time.deltaTime;
     wrappedValue = Mathf.Repeat(loopingValue, 100f);
     loopCount = Mathf.FloorToInt(loopingValue / 100f);
 }
 
               Warning: Above has not been tested, but hopefully this should demonstrate the basic idea.
Your answer
 
             Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Get 360-degree rotation in on-screen directional arrow? 0 Answers
Finding Distance between Angles and Points 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer