Using mutliple buttons for a common goal new UI system help

I need help! I’m not used to the new Unity UI system, as far as I know you can only add individual scripts to buttons. However, in my situation I want one script to handle the functionality of many buttons attached to an empty game object or something. Heres an image of what I want to try and program currently:

For the current arrow buttons I want the word to change from skin → hair - > eyes as pressed accordingly, how would I go about this with the new system? Make a global integer variable and use that in each button script??

Hi! Attach the script to the canvas or other game object :smile: You can pass it a button specific variable too if needed!

1 Like

Hey, thanks for the reply but how do I access the buttons via code? I have to increment or decrement depending on the button being pressed up to 3 times. So instead of just changing the text once depending on the button if i hit right from state 1 itll go to state 2 if i hit left from state 2 itll go to state 1. I need a unifying variable between the 2 buttons keeping track of the integer state.

I think you just solved the problem yourself :wink: Maybe use a switch, or an array, or pass the name of the image you are displaying :smile: Just thoughts and ideas :slight_smile:

1 Like

Im more asking related to syntax, I understand the logic, I know how to do this with the old OnGUI() system, i just dont know how to have a global variable between 2 buttons now that they each generally require a separate script… ya know what i mean? or am i just being stupid XD

They don’t require a separate script, but if you wanted to do it that way you still could :slight_smile: To make a variable accessible in C# use:

public String myString;

void Start(){
}

Or whatever Type you are using :smile: