#On Trigger With Sound
1 messages · Page 1 of 1 (latest)
Update: I changed to code to look like this and attached the sound file to a gameobject then referenced that object in the inspector. It now will play on awake but when i untick and go through the collision nothing happens.
Okay, i looked up another tutorial, I've changed my script again, I have tested the sound by adding another track, but still the clip doesn't play
Are you using the correct method? Is your collider set to IsTrigger?
my collider is yes, the collection system is working perfectly alongside a timer script, it just wont play the sound.
I also did a debug in the if statement and that worked when i triggered the object
Is the audio source active? Did you assign it from the inspector?
I believe so, but just to be sure here's a look
Does the object this script is attached to have an audio source? Bcuz you get the audio source component in Start . . .
that audio source is attached to the object
When you play the game, pause it and check that tickSource is not null from the inspector . . .
Where is/did you place the log to check the trigger runs. I don't see it?
ill check that now!
i think i got it
nope nevermind
hhaha
okay so i made a new game object called audio
and attached the sound file to that
then i dragged it onto my tick source
this works if i do it after i play the game, pause and then add the audio to that source
Oh, comment out the Destroy line and test if the sound works . . .
I just wanted to make sure the component wasn't null. If you play then pause and check the variable, it should be populated . . .
Makes sense. When you destroy the object, all of its components are destroyed as well. The audio source gets destroyed and the sound stops playing (right when you play it), so it never runs . . .
okay that makes so much sense
im trying to think of alternatives
really I just want the sound to play to showcase in my project i know how to use sound clips with on trigger events
how would i instantiate the destroy function after the play ?
I could try on triggerenter for the sound and on exit destroy 😮
im gonna try that
🙂
yay c#
..... that was premature
i added the tick source to the destroy function thinking it would play when the function is called
maybe this doesnt work or its my syntax but i dont understand why it wouldnt
it never reaches my second debug "Hello2"
Update: I'm 90% of the way there, the sound now plays on collision and stops after i exit , the remaining issue is that it stops immediately, meaning if the player is running to fast they wont hear the clip as the exit the collider to fast any ideas on how to resolve this ?