- Home /
This question was
closed Mar 31, 2015 at 05:39 PM by
tanoshimi for the following reason:
The question is answered, right answer was accepted
Float and deltaTime problems?
I'm trying to make a rhythm game but I can't seem to get the code right. I want the ticks to show in the console every half a second but it won't show the console. Is it because there's a conflict with the data type float and deltaTime? I want it to be 0.5 seconds because that is when the beat drops, meaning I can't use int as my data type.
Here's the code:
#pragma strict
public var ticks : float = 0;
function Update () {
ticks += 1 * Time.deltaTime;
if ( ticks % .5 == 0 ) {
Debug.Log (ticks);
}
}
Comment
Best Answer
Answer by Graham-Dunnett · Mar 31, 2015 at 11:28 AM
#pragma strict
public var count : int = 0;
public var ticks : float = 0.0f;
function Update() {
ticks += Time.deltaTime;
if (ticks > 0.5f) {
count += 1;
Debug.Log(count);
ticks -= 0.5f;
}
}