Quantcast
Channel: Answers by "ransomink"
Viewing all articles
Browse latest Browse all 80

Answer by ransomink

$
0
0
You can do at least two different approaches: The first one rounds the float to two decimal places to avoid floating point imprecision. private int _iteration; private float _timer = 0f; void FixedUpdate() { if ( _timer < 0.2f ) { _iteration++; _timer += Time.fixedDeltaTime; _timer = ( float )System.Math.Round( _timer, 2 ); Debug.Log( "Iteration: " + _iteration + " | Timer: " + _timer ); } } - The second one uses Mathf.Approximately to compare two floats using Epsilon as a tolerance. private int _iteration; private float _timer = 0f; void FixedUpdate() { if ( !Mathf.Approximately( _timer, .2f ) ) { _iteration++; _timer += Time.fixedDeltaTime; Debug.Log( "Iteration: " + _iteration + " | Timer: " + _timer ); } }

Viewing all articles
Browse latest Browse all 80

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>