Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
How can I let music play over several scenes without the music restarting every scene?

I am very new to Unity and C# and I have a problem with my Audio. The music plays from the beginning everytime i load a scene. How can I let the music play over several scenes without the music restarting?(Sorry for the bad english) The code I am using is a simple code to adjust the music volume via slider and save the volume across multiple scenes. I am using the unity 2018.3.14f1 version.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;

public class Volumemultiplelevel : MonoBehaviour
{
    public AudioMixer mixer;


    void Start()
    {
        SetLevel(PlayerPrefs.GetFloat("MusicVol"));
    }

    public void SetLevel(float sliderValue)
    {
        PlayerPrefs.SetFloat("MusicVol", sliderValue);
        mixer.SetFloat("MusicVol", Mathf.Log10(sliderValue) * 20);
    }
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can create a new gameobject with a script and the audio source. The script has to check if it isn't already playing (you can do that with some static bool) and play.

This will make your gameobject (with the audiosource) not get deleted DontDestroyOnLoad(musicPlayer)

Put the gameobject in the starting (menu) scene

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda