Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Switching audio when a character reaches a certain point in a scene.

Discussion in 'Audio & Video' started by asiansteve, Jun 24, 2015.

  1. asiansteve

    asiansteve

    Joined:
    Mar 23, 2015
    Posts:
    6
    I have a 2d side scroller game where at the start of the level there is a theme for a new character who is introduced. But once he is off screen I'd like a new sound effect to play as a transitional effect. After that sound effect finishes then new level music starts.
     
  2. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
  3. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    A snapshot can't do that alone, to my understanding.

    I'd use a Becomes Invisible event from MonoBehavior and play a sound when the character becomes invisible (off camera). Then I'd keep checking that Audio Source until it's not playing, and then have code change the level music (possible with a mixer snapshot if you want crossfading without having to code it).
     
    aihodge likes this.
  4. asiansteve

    asiansteve

    Joined:
    Mar 23, 2015
    Posts:
    6
    Thanks I'll try that!

    Would using a collider be more beneficial if I wanted to keep the character on screen and trigger a new sound effect and animation, when my PLAYER walks to a certain spot?
     
  5. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Yes it would. A "trigger" colliders to be precise.
     
  6. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    jerotas' approach is correct here - my answer was too simplistic and would not cover waiting until the transitional sound had finished playing. Sorry!