Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to make a cross scene mute and unmute button.

Discussion in 'Scripting' started by itsdandd, Jul 12, 2020.

  1. itsdandd

    itsdandd

    Joined:
    Jan 6, 2020
    Posts:
    44
    I want to know how to make a cross scene mute button and unmute button. I have tried a dontdestroyonload for seamless music but I dont know how to make a mute and mute button for it. Any ideas?
    Thanks!
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    itsdandd likes this.
  3. itsdandd

    itsdandd

    Joined:
    Jan 6, 2020
    Posts:
    44
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    How to change the way what looks? The button?
     
    itsdandd likes this.
  5. itsdandd

    itsdandd

    Joined:
    Jan 6, 2020
    Posts:
    44
    The sliders. Sorry for not clarifying.

    Also, is there a way to move it somewhere else?
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Of course. If you look at the slider in your scene hierarchy you'll see it's actually made of a small hierarchy of different GameObjects. I encourage you to poke around in there. For example, there's an image component for the "handle", there's an image component for the "filled" area, there's an image component for the "unfilled" background. You can change these sprites to your liking.

    As for positioning, yes of course. A slider is like any UI element in Unity. Here's an article about how positioning UI elements works in Unity: https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/UIBasicLayout.html
     
    Last edited: Jul 13, 2020
    itsdandd likes this.
  7. itsdandd

    itsdandd

    Joined:
    Jan 6, 2020
    Posts:
    44
    I cant find the slider in the hierarchy. I applied the script to my empty gameobject with the music player and I didn't have to even make a slider it made one its self. Did I apply it wrong? Thank you for helping me so far!

    It made this itself:
     

    Attached Files:

  8. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Ok so I just realized you're probably talking about the example script from this link: https://docs.unity3d.com/ScriptReference/AudioSource-volume.html

    Is that correct? That script is just an example of how to use the "volume" property of an AudioSource from a script. You aren't meant to copy the script into your project. It's using the outdated OnGUI method to draw that slider, which is much harder to customize than the modern Unity UI.
     
    itsdandd likes this.
  9. itsdandd

    itsdandd

    Joined:
    Jan 6, 2020
    Posts:
    44
    I did copy it. I dont know much about scripting though.
     
  10. itsdandd

    itsdandd

    Joined:
    Jan 6, 2020
    Posts:
    44
    Is there any tutorials I could watch to help me?
    Thank you for replying!