The question is answered, right answer was accepted
Audio Source and Slider remove themselves from script during runtime
I'm currently trying use PlayerPrefs to allow the player to save their audio settings.
I have linked the audio source that's connected to the main camera to a script that loads the PlayerPrefs.
There is also the volume slider that sets itself according to the volume saved.
When I run the game, both Audio Source and Slider get removed from the Script but re-appear after exiting the game.
Answer by MinyMunchies · Aug 01, 2021 at 11:12 PM
I figured out the issue. I was referencing the Audio Source and Slider with GetComponent which looks for the components attached to the GameObject. I didn't have those attached to the GameObject because I wanted to use an already existing Audio Source and Slider.
I used tags on both GameObjects that had the components I wanted to reference and used FindGameObjectWithTag in the script. It now does what I want it to do.
Follow this Question
Related Questions
Making a slider, slider does nothing even when attached to the script? 1 Answer
InverseLerp for vector3 1 Answer
i try make enemy health slider or any uI just show the health of Enemy Over head 0 Answers
How to decrease a Slider value by time? 1 Answer
Why is the color of the player not changing properly? 1 Answer