Accurate timing for Rhythm Game?

I want to play an audio clip at a specific number of seconds from the time my game starts. I’m using an if statement to check the seconds that have passed against the time I want the clip to play.

	void Start () {
        startTime = Time.time;
    }
	
	void Update () {

        currentTime = Time.time - startTime;

        if (currentTime == 10) audio.Play;
   }

but the clip never plays. It seems that the timer reaches the value in between updates, so it never plays the clip. Is there a way to more accurately time things?

I’m not really sure about your methods… If you want a timer to count forewards or backwards you should be saying currentTime+=Time.deltatime; or currentTime-=Time.deltatime;… Then your asking if time is 10 then play audio. Its very possible this might never occur… Time is a float value, yes it will reach 10, but the chances that it will reach exactly 10 are kinda low(in that frame it might only reach 10.0001 for example). You need to say, if(currentTime>=10).

As brilliantgames said, Time.time is a float and is likely never to equal 10 exactly.
Using the if(currentTime >=10) would produce its own problem though; Which is that the audio would continually be requested to play after 10 seconds.

Instead use Invoke method to do something after x amount of time, example:

void Start () {
   Invoke ("PlayAudio",10);
}

void PlayAudio () {
   audio.Play();
}

Hope this helps!