Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question What is a good way to keep this sound from chopping?

Discussion in 'Audio & Video' started by jleven22, Apr 13, 2023.

  1. jleven22

    jleven22

    Joined:
    Mar 26, 2019
    Posts:
    397
    Here is a link to the video/ sound:
    https://imgur.com/a/y8TF0ao

    As you can see the XP reduction at the end has a sound, and it's clipping.

    Script:

    Code (CSharp):
    1. if (shouldRunUpdate)
    2.         {
    3.             if (UIController.instance.shouldCountDownMagicXP)
    4.             {
    5.                 if (UIController.instance.magicXP > 0)
    6.                 {
    7.                     UIController.instance.magicXP -= 1000f * Time.deltaTime;
    8.                     UIController.instance.magicXPText.text = Mathf.FloorToInt(UIController.instance.magicXP).ToString();
    9.                     AudioManager.instance.PlaySFX(magicAddSound);
    10.  
    11.                     if (UIController.instance.magicXP > 0 && UIController.instance.magicXP < 200)
    12.                     {
    13.                         UIController.instance.magicXPIcon.gameObject.GetComponent<UIMagicXPIcon>().anim.SetTrigger("fill");
    14.                     }
    15.                 }
    16.                 else
    17.                 {
    18.                     UIController.instance.magicXPText.text = "0";
    19.                     UIController.instance.shouldCountDownMagicXP = false;
    20.                     Debug.Log("shouldCountDownMagicXP = " + UIController.instance.shouldCountDownMagicXP);
    21.                 }
    22.             }
    23.             else
    24.             {
    25.  
    26.                 StartCoroutine(UIController.instance.DeathScreenActivator());
    27.             }
    28.         }
    Sound is triggering on line 9. I understand why it's happening. So I could really use some help thinking of clever ways to fix the choppiness here.

    Any thoughts?
     
  2. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    290
    Maybe you could play the sound once, but set it to loop instead of triggering it at each update.
     
  3. jleven22

    jleven22

    Joined:
    Mar 26, 2019
    Posts:
    397