#Timers and Audio

1 messages Β· Page 1 of 1 (latest)

earnest tinsel
#

help

dusty latch
#

It's possible that audio doesn't like what we're trying to do but we'll see when the code is up πŸ™‚

earnest tinsel
#

whats the site called again?

dusty latch
#

I click randomly but others have a preference

earnest tinsel
dusty latch
earnest tinsel
#

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

dusty latch
#

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

earnest tinsel
#

it doesnt :/

dusty latch
#

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

earnest tinsel
#

heh

#

if it drops to 0 does it restart?

#

oh it does

#

nice let me give it a shot

dusty latch
#

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

earnest tinsel
#

why < 5 btw?

dusty latch
#

Just a placeholder for the "cliplength" variable

earnest tinsel
#

isnt the clip length for += 4?

dusty latch
#

Which you could likely set to the middle "if else"

#

Indeed

#

Mainly get this working, then when you add other things you'll tweak

earnest tinsel
#

so both += cliplength and < cliplength?

#

hm

dusty latch
#

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?

earnest tinsel
#

they are

dusty latch
earnest tinsel
#

I see

dusty latch
#

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

earnest tinsel
#

time doesnt exist in current context

dusty latch
#

Not sure what you mean

earnest tinsel
dusty latch
#

Capital T?

#

Time.deltaTime

earnest tinsel
#

nice lol

#

LETS GOO

dusty latch
#

xD

earnest tinsel
#

a fuck

#

it only works once

#

no nvm

#

so

dusty latch
#

xD

earnest tinsel
#

AH i found the fix

dusty latch
#

πŸ₯³

earnest tinsel
#

NICE

#

IT WORKSS

#

β™₯β™₯β™₯

#

TYSM

dusty latch
#

Huzzahhhh!

#

What's the fix? πŸ˜‰

earnest tinsel
#

πŸŽ‰

#

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

#

πŸ‘

dusty latch
#

Depending on how many sounds you have it may end up moving to a new function but HAVE FUN! πŸ™‚