I have a problem with creating buttons from an arraylist.
Here is some sample code to show my problem:
//////////////////////////////////////////////////
Texture2D tex ;
.
( code to insert textures into tex)
.
voidOnGUI(){
for(int i =0; i < tex.Length; i++)
(GUILayout.Button(tex[ i ]));
} /////////////////////////////////////////////// The problem is I get the correct number of buttons created,however they all share the texture name, so I end up with “n” number of buttons all with texture “n”. For example if my array contained textures [A,B,C], I would see the buttons being created in the following order: A → BB → CCC How could I define each button to have its own texture from the arraylist? Thank you.
Thank you for this, I found out I was doing a for loop twice so I was getting more values entered into my array than needed.
I managed to fix that and now get the correct number of buttons and each has its own texture, however the next texture deletes the previous texture, so I end up with for example 5 blank buttons and one with the texture of the last texture in my array.
I did try to create a string and texture created from my text [ i ] array but no luck.