Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Resolved Problems with sound playback

Discussion in 'Audio & Video' started by Gabo19x, Mar 9, 2021.

  1. Gabo19x

    Gabo19x

    Joined:
    Oct 23, 2020
    Posts:
    104
    Hi, I have a problem with a sound, the sound is imported into the project... But when running the game the sound does not play, in the script passes through the line (using the .play() ) of the code but does not sound, why this?
    In addition I have a background song, and it plays normally; when I activate the loop option or play on awake in the Audio Source of the sound that doesn't work: it runs normally
     
    Last edited: Mar 9, 2021
  2. andrescuevas

    andrescuevas

    Joined:
    Apr 23, 2019
    Posts:
    24
    I have the same problem. I have seen a lot of posts about this but no answers. Did u manage to figure it out?
     
  3. Gabo19x

    Gabo19x

    Joined:
    Oct 23, 2020
    Posts:
    104
    What exactly is the problem, is with the whole sound system, or it is only with a specific sound
     
  4. Gabo19x

    Gabo19x

    Joined:
    Oct 23, 2020
    Posts:
    104
    My problem probably has to do with the script, as other sounds run correctly

    Code (CSharp):
    1. public class BarraVidaPeleador1 : MonoBehaviour
    2. {
    3.     public Image barraVida;
    4.     public float vida;
    5.     public float VIDAMAX;
    6.     public GameObject peleador1;
    7.     [Header ("La luz del contrario")]
    8.     public GameObject luz;
    9.     [Header ("Partes y posiciones")]
    10.     public GameObject brazoIz;
    11.     public Transform posBrazoIz;
    12.     public GameObject brazoDer;
    13.     public Transform posBrazoDer;
    14.     public GameObject piernaIz;
    15.     public Transform posPiernaIz;
    16.     public GameObject piernaDer;
    17.     public Transform posPiernaDer;
    18.     public GameObject cabeza;
    19.     public Transform posCabeza;
    20.     public GameObject cuerpoP1;
    21.     public Transform posCuerpoP1;
    22.     [Header ("Sonidos")]
    23.     public AudioSource sonidoMuerte;
    24.     public AudioSource sonidoVictoria;
    25.  
    26.     void Update()
    27.     {
    28.         barraVida.fillAmount = vida / VIDAMAX;
    29.        
    30.  
    31.         if(vida <= 0)
    32.         {
    33.             Sonidos();
    34.             luz.SetActive(true);
    35.             CreacionMiembros();
    36.             Invoke("CambioEscenaMenu", 4f);
    37.             Invoke("Desactivacion", 1f);
    38.         }
    39.     }
    40.  
    41.     private void CambioEscenaMenu()
    42.     {
    43.         SceneManager.LoadScene("Menu");
    44.         luz.SetActive(false);
    45.         Invoke("Activacion", 2f);
    46.     }
    47.  
    48.     private void Sonidos()
    49.     {
    50.         sonidoMuerte.Play();
    51.         sonidoVictoria.Play();
    52.     }
    53.  
    54.     private void Activacion()
    55.     {
    56.         peleador1.SetActive(true);
    57.     }
    58.  
    59.     private void Desactivacion()
    60.     {
    61.         peleador1.SetActive(false);
    62.     }
    63.  
    64.     private void CreacionMiembros()
    65.     {
    66.         GameObject miembro;
    67.         miembro = Instantiate(brazoIz, posBrazoIz.position, posBrazoIz.rotation);
    68.         miembro = Instantiate(brazoDer, posBrazoDer.position, posBrazoDer.rotation);
    69.         miembro = Instantiate(piernaIz, posPiernaIz.position, posPiernaIz.rotation);
    70.         miembro = Instantiate(piernaDer, posPiernaDer.position, posPiernaDer.rotation);
    71.         miembro = Instantiate(cabeza, posCabeza.position, posCabeza.rotation);
    72.         miembro = Instantiate(cuerpoP1, posCuerpoP1.position, posCuerpoP1.rotation);
    73.     }
    74. }
    75.  
     
  5. argh6543

    argh6543

    Joined:
    Apr 14, 2017
    Posts:
    48
    Same issue here. Worked in 2020.2.x, but broke when I updated to 2020.3.0f1... Haven't touched the script I used in a couple of years...
     
  6. Gabo19x

    Gabo19x

    Joined:
    Oct 23, 2020
    Posts:
    104
    But what broke? the whole script or the parts of the sounds?
     
  7. Gabo19x

    Gabo19x

    Joined:
    Oct 23, 2020
    Posts:
    104
    Hello!?
     
  8. Gabo19x

    Gabo19x

    Joined:
    Oct 23, 2020
    Posts:
    104
    I fixed it every time an enemy died, I created an empty object with the sound, I also put a script that controlled the time, a generous time to sound correctly