Hey guys, a little issue that I’ve never encountered before and hoping you could shed some light on it for me. I have an array of buttons (30 to be exact) which I store like so:
var Grids : GUIContent[];
I know it will be in function OnGUI() what I have to do but I cannot find a snippet of the code anywhere. Say I wanted to click button 25 and print to the console, how would I go about this? I’m probably missing something extremely simple.
if (button 25 is pressed){
Debug.Log("We clicked button 25");
}
What the heck goes into that if statement? ![]()
Thanks. Additionally, is there anyway to do this without creating a new button and just click the ones already created?
– Nercoeyou may have to show some more code, as I do not understand how you are storing buttons or why you have buttons already created. You should just be able to create that array of GUI content then create each button within an if statement
– roojerryWell what I am trying to do hasn't been implemented yet. I'm just researching before I start coding. What I need is basically: If button 25 is clicked and it has a texture of a gun on there, print to console. I know how to handle the texture check and most other things, I've just never needed this before. So my array is named "Grids". I need to check if ANY button at all is pressed in there, is there anything like "GUI.Button.Grids[]"?
– NercoeAs far as I know there isn't a way to do what you are after because you don't really store buttons. The call to GUI.Button(...) draws the button for you each frame and returns a bool as to whether or not it has been clicked that frame. You are simply storing the content you want drawn on each button.
– roojerryFigured it out, wow it was so simple haha! Check this out: if (Grids[1]) { Debug.Log("Easy"); } haha thanks for all your help, I really appreciate it :)
– Nercoe