#Timers and Audio
1 messages Β· Page 1 of 1 (latest)
It's possible that audio doesn't like what we're trying to do but we'll see when the code is up π
whats the site called again?
I actually found this which may be better for you than my looping - https://forum.unity.com/threads/audio-looping-not-consistent.475605/
thing is
because my if{} is inside the Update(), every time it detecs that its on wood the sound plays
and it just sounds like an error sound because it just plays again and again, so you can only hear the beginning
Yeah, the .loop property of AudioSource should hopefully get around that
If not you'll likely have to set a bool to check if true within Update() and have the code in a separate function
Unfortunately I've not got to sound in my game yet so I haven't worked with those properties specifically
it doesnt :/
I'm just reading your code again
{
s.source.Play();
elapsedTime += 4;
elapsedTime -= time.deltaTime;
}
else if (elapsedTime < 5)
{
elapsedTime -= time.deltaTime;
}
else
{
elapsedTime -= time.deltaTime;
}```
I'm just checking but if you set the length of the clip somewhere else, then push it to that, it won't matter how long the audio is
I found that I needed 3 statements to make sure that the code loops correctly
But I have a different use xD
Okay, I see you have cliplength already π
Main changes, instead of checking for exactly 0, you're better off checking <= Since update may not always give you 0 since we're using deltatime
You didn't need to compare it to anything else since it's kinda irrelevant
why < 5 btw?
Just a placeholder for the "cliplength" variable
isnt the clip length for += 4?
Which you could likely set to the middle "if else"
Indeed
Mainly get this working, then when you add other things you'll tweak
You're better off getting it to work with hard values to begin with so it's less to debug
I set 4 & 5 as it's longer than the 3 for the clip?
they are
Yeah, so it essentially starts counting down in the same loop instead of waiting for the next Update()
I see
And you want += in case the value is -0.042 .... the new value will be 4.042 ; so discrepancies don't build up over time
time doesnt exist in current context
Not sure what you mean
xD
xD
AH i found the fix
π₯³
π
your code worked perfectly, its just that when i stopped touching would i called for a stop
but the timer kept counting
so if i touched again while it was counting the sound didnt play until the timer hit the cap
so i just slapped an elapsedTime = 0 in the else
π
Depending on how many sounds you have it may end up moving to a new function but HAVE FUN! π