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

256
Visualizações
If and ActiveSelf. Only works once. With example project

First time developer here and I am struggling with a problem. I made a mock up of the problem in regular Unity 3d since the VR scares some talented people away from helping me. That can be downloaded here: https://gofile.io/d/qHDlUZ File is a zip called: SoundTestTroubleShooting. A Unity build on 24.7MB Follow the number on the buttons. Button 1 "Choose Music" Activates the Cube. Button 2/4 "Play Music" Checks if cube is activated and plays song if that is the case. Button 3 "Restart Scene" Stops the music and reloads the scene. Cube has dontdestroyonload. After that i press button 2/4"PlayMusic" and it cant find that the cube is active. WHY?! Going nuts here.

Old text with the entire problem here:

In my game I have four songs in the start menu that my player gets to choose from. He chooses one by pressing one of four buttons. This activates an empty GameObject, lets call it SmileMusicTrigger. SmileMusicTrigger has a dontdestroyonload and is deactivated by the other three buttons if player wants to switch song.

Player press Begin which moves him into position. He presses start and this button has:

 public GameObject SmileMusicTrigger;
public GameObject EpicMusicTrigger;
public GameObject GodMusicTrigger;
public GameObject VikingMusicTrigger;

void OnTriggerEnter()
   {
    if (SmileMusicTrigger.activeSelf)
    {
        AudioManager.instance.Play("Smile");
    }
    if (EpicMusicTrigger.activeSelf)
    {
        AudioManager.instance.Play("Epic");
    }
    if (GodMusicTrigger.activeSelf)
    {
        AudioManager.instance.Play("God");
    }
    if (VikingMusicTrigger.activeSelf)
    {
        AudioManager.instance.Play("Viking");

and my game start and and the music begins fine. When player dies he restarts the scene with restart button which has this to say about the music:

   void OnTriggerEnter()
{
    AudioManager.instance.Stop("Smile");
    AudioManager.instance.Stop("Viking");
    AudioManager.instance.Stop("God");
    AudioManager.instance.Stop("Epic");

} }

after this code has run the scene restarts and it does not seem like my Start button can check the active state of SmileMusicTrigger again. I know SmileMusicTrigger is active through the restart of the scene because I see it under dontdestroy in the hierarchy when game is running and it is checked as on in inspector. But I cant seem to call it again. Thus my music only plays once.

Audiomanager is also under Donotdestroy so I dont think the problem is there.

Sorry if this is messy. I am working really hard to get this working but I am so stuck right now. Thankful for any help. All the best!

over 4 years ago · Santiago Trujillo
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