Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Triggers, Collisions, Scripts and Audio

Is it possible to have separate scripts for Player Control, Trigger events and/ or Collision Events and Audio?

I have a Player object that moves around the play area picking up sums, (4+4=8, 4+4=4) on picking up the correct sum and answer the sum disappears and a sound is played, but when it comes to the sum with the wrong answer, I cannot figure out how to get it to do anything. Unity 2019.4 (that I'm using, complains about more than one trigger or audio source being used in a script or on an object (player in this case), I have tried separate scripts but cannot get that to work. I have also tried OneShotPlay regarding the second audio sound. At the moment the correct answer trigger and audio source are in the Player Controller script and it works. (AudioSource is attached to the player Object. Tried AudioClip but cannot get that to be recognized in script or attaching to any other game object. Will be trying the Audio Manager shown in one of the videos.

All gameObjects except menus have rigidBody and Box or Capsule Colliders.

I would like it to play a sound for the wrong sums as well which I would like to have left in place.

Thanks in Advance for any help or advice offered.

Best Answer

  • MouledouxMouledoux Member
    Accepted Answer

    Is it possible? Yes absolutely. It's actually the better way to do it. Keeping your scripts separate makes it easier debug, and expand on later.

    If the audio clips only play on trigger or collision event, those could be in 1 script. Unless you have a manager for the audio, but just to play a buzzer sound, not necessary.

Answers

Sign In or Register to comment.