Create multiple object slightly different (SOLVED)

I’m sorry i’m very newbie.
I would like to create multiple buttons with an alphabet letter on eachone, when pressed i would like to play a voice that says the letter.
I created a button with the gui, but the sound can be attached only to game object, so maybe the gui is not the right choice.
How do you suggest to proceed? Is there a way to automate with code the creation of the buttons, or i have to manually design them all?

Even though you’re not able to attach sounds to a gui I’d still use it. Something like this:

  1. Create a single button in your gui scene. Consider this to be a template/prefab for all of the buttons.
  2. Use gui.clone_tree() to make multiple copies of the button.
  3. Change the text in the text node of each button.
  4. Store each created button in a Lua table
  5. Detect input and match it to the correct button
  6. Create a game object with all of the sounds
  7. When you know which button was pressed you send a message to the correct sound component and have it play the sound.

I’ll create an example showing this. I’ll post it here when done.

Example: https://github.com/britzl/publicexamples/tree/master/examples/dynamic_buttons

Demo: http://britzl.github.io/publicexamples/dynamic_buttons/index.html

4 Likes

Thanks!