Hi guys, I need a little help here.
I want to create a rhythm game for android and I need enemy to appear on screen on a specific time matching with the music.
I’ve wrote this piece of script that makes me go out of sync:
for(var k = 1; k < time_s.Length; k++){
if(gameover)
return;
var lack : double = Time.time;
print(Time.time);
Instantiate(enemy_s[k-1],myTransform.position,myTransform.rotation);
lack-=Time.time;
print(Time.time);
yield new WaitForSeconds(wait[k] -lack);
}
Problem is that Instantiate does take it’s time and it’s added to the instantiation of the enemy, making the game out of sync after 20-30 enemys.
I’ve tried to evade this problem by using the lack variable that should store the instantiation time and subtract to the wait, but Time.time only have 4-5 decimal and lack is always 0.
Does exist a Time.time more precise or can you guys help me finding another way to do it?