I have an Audioclip which plays when the scene starts, I want to highlight an object in the scene at a specific moment in time, lets says 15 sec from the start of the Audio clip. Is there anyway I can achieve this?
the AudioSource component has a time variable. you could check if it’s greater than 15 to fire off the event. use a bool to do it only once.reset the bool when the time is smaller (starting from the beginning) then last frame (time always saved after checking each frame)
I went ahead and use empty Animator controller with Event attached to the Audioclip Gameobject. Thou I don’t know if it’s the optimum way.
The Invoke() method has an optional second parameter that allows you to call a method after a certain amount of time. So you can queue your objecthighlight method to fire after a specified amount of time from the point you start the audio:
void PlayTheAudio() {
// Start the audio clip playing
audioSource.clip = yourClip;
audioSource.Play();
// Call the HighlightObject method 15 seconds from now
Invoke("HighlightObject", 15f);
}
void HighlightObject() {
...
}