Getting nullReferenceException when respawning a gameObject and trying to access the audio source.
Hello,
in my game I have different objects which keep respawning using lists and traveling from the right side. The objective of the game if for the player to catch the objects which he is supposed to catch and avoid the objects which he isn't supposed to catch.
My problem is that using lists to create new gameObjects creates them endlessely and I am forced to destroy the ones that have been created by using a OnTriggerEnter2D method which destroys the object on enter. Now, I am trying to implement sounds on when the player enters the collider of the gameObject itself. And in the beginning of the game it works but however, after the first gameObject has been destroyed it throws up a nullReferenceException.
MissingReferenceException: The object of type 'AudioSource' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object
And the reason I am destroying the gameObjects is that they spawn endlessely and can potentially overflood the system which will effect the performance.
Please help.
Your answer
Follow this Question
Related Questions
How to play audio while reloading a weapon ammo in unity 3d C# Scripting ? 0 Answers
maybe audiosource problem 1 Answer
How to Play sequentially more than one AudioSource in one game object ? 1 Answer
Destroy GameObject or 2D collider does not work 1 Answer
How to Respawn an gameObject when it touch another gameObject 1 Answer