Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

258
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda