- Home /
Making button sound components to many button instances?
Hello. I'm making menu button sounds and I have three components to do that. audio source component, sound script component, and a event trigger component. I don't want to just copy and paste same three components to every button since there's many of them. How to make the three components effect multiple button objects? Thanks
Answer by Digger8048 · Dec 02, 2019 at 01:27 AM
Why not add the components with a script?
something like: Button allButtons = transform.GetComponentInChildren(); foreach(var button in allButtons) { button.gameObject.AddComponent(); button.gameObject.AddComponent(); button.gameObject.AddComponent(); }
Answer by Neran28 · Dec 02, 2019 at 03:46 AM
I dont quite undrrstan the question. Is it to time consuming adding the components or do you want to have a the sound handling more structured. If you just wanted to copy paste the components then you should have used prefabs.
You can also use just one gameobject that handles the sound for the ui with script and audiosource attached. Then onclick call whatever the sound triggers to play. If you want to have the buttons use different sounds you can use scriptable objects containing audioclip volume etc and pass them to the gameobject that handles the sound.
Your answer
Follow this Question
Related Questions
Unity can't see any scripts 0 Answers
Destroy all scripts on object. 3 Answers
How to make namespaces appear in the AddComponent List automatically? 2 Answers
How to make sure custom init methods are called? 1 Answer
Destroy specific joints 1 Answer