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

How to lower the volume of my BGM

Discussion in 'Scripting' started by feit0719, Jan 21, 2020.

  1. feit0719

    feit0719

    Joined:
    Dec 5, 2019
    Posts:
    6
    I want to lower the volume of my BGM that is on DontDestroyOnLoad on the next scene on Start without a slider?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class BG : MonoBehaviour
    6. {
    7.     private static BG instance = null;
    8.     public static BG Instance
    9.     {
    10.         get { return instance; }
    11.     }
    12.     private void Awake()
    13.     {
    14.         if(instance != null && instance != this)
    15.         {
    16.             Destroy(this.gameObject);
    17.                 return;
    18.         }
    19.         else
    20.         {
    21.             instance = this;
    22.         }
    23.         DontDestroyOnLoad(this.gameObject);
    24.     }
    25. }
    26.  
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    The code you posted doesn't appear to have anything to do with playing music, and if you don't want to use a slider you might want to state what you do want to use.

    But most likely just setting the music AudioSource's volume to whatever you want is what you're looking for.

    https://docs.unity3d.com/ScriptReference/AudioSource-volume.html