I know that this post is very old but I’ve a really big problem with AudioSource.time property: IT DOESN’T SEEMS TO WORK IF YOU TRY TO ASSIGN IT A VALUE !!!
I’ve also tried to post in another topic of mine this problem but nobody has answered to me
In specific I’m trying to do:
/// <summary>
/// called to start the sound play
/// </summary>
private void playSound () {
if (audio) {
audio.time = 1.74f;
Debug.Log ("audio time when started = " + audio.time);
audio.Play ();
} // if
} // playSound
but it seems to start always at 0.0f !!!
Am I wrong, or there are some problems?
Please… let me know something about !!!
If you’re interested here you can find my other post about audio manipulation.
Ok… it works !!
But wait a sec: if a need a precision of starting a sound at the order of 0.001 sec why I cannot have the possibility to seek the sound cursor BEFORE to play the sound? I mean, if I seek the cursor after playing the sound could it cause some lack of time? If I have to synchronize the sound with an animation this must be very annoying.
I don’t think so…those lines of code are executing during the same frame. So you tell the sound to play, and then tell it what time, and it will start playing at that time.
In fact I’ve done some others tries but… there are a lot of strange behaviours about this property. have you noticed that this instruction will be executed 2 times each call?
If you’re making the call from inside OnGUI() – which you shouldn’t be --, then 2 calls per frame is by design. OnGUI() always gets called twice per frame, once for layouting and once for rendering.
If you’re not making the call from inside OnGUI(), then two executions of an instruction is a bug and please report it using the Bug Reporter.