Can not play a disabled audio source?

Hi,

I have 5 cube that all 5 cube have audiosource. When my player jump into those cubes, the audiosource is playing(just once). It was working. But then, I decided to organised my hierarchy and audiosource didn’t work well.
When I jump to first cube, the audio is playing but then ıf I try to jump to the other cubes, audio is not working. (Actually the cube is prefab and all 5 cubes are the created from that prefab). It gives “Can not play a disabled audio source” and I don’t know why ? Because I haven’t changed about coding part.

This is my first cube component :

The other 4 cubes (actually they all the same as with the first cube ) :



    [SerializeField] AudioSource clickSound;
    

     bool landedorNot = false;

     void Start()
    {
       
    }

    

    private void OnCollisionEnter(Collision collision)
    {

        if (collision.gameObject.name == "Ship New Pos" && landedorNot == false )
        {
            landedorNot = true;
            
            if (!clickSound.isPlaying)
            {

                clickSound.Play(); // this is where the error occurs according to Unity
            }

        }


    }

Thanks advance

Hi Alpay,

First of all, good job on challenging yourself. :slight_smile:

Regarding the problem, to which class does the code belong? And to which game object is it attached? Have you already tried to add Debug.Logs to your code to see what is going on during runtime?

If your Paddel game objects are moving, add a Rigidbody component to them.

I don’t know why but when I deleted audiosource and added again, ıt fixed the problem :thinking:

Sometimes, the components in Unity are a bit buggy. Removing and readding often fixes issues. Maybe that was the case here.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms