Hello Everyone!
I have a repetitive pattern in my functions. It’s working, but I know that is a terrible approach.
The thing is: I have 4 buttons, each one is enabled by a boolean in a separated script. When I press 1 of them, I need to disable the other 3.
Thank you! I see how I can use a loop to disable the other 3 Buttons.
But I’ll still need 4 methods to ‘turn on’ the clicked task.
I wonder if theres a way to get the ‘id’ of the button, to reach something like this:
void Task()
{
for (int i = 1; i <= numberOfTasks; i++)
PlayerPrefs.SetInt("task" + i, taskNum == i ? 1 : 0);
PlayerPrefs.SetInt("IDButton", IDbutton ? 1 : 1);
}
which the loop would disable all buttons, and the single command below would enable just the clicked button.
Or even better, if the loop could make an exception, and dont change the current bool state of the ‘IDButton’
I don’t quite understand the problem you’re having with my code, it already sets the int of the correct task to 1 given the parameter of the method, and turns the rest to 0. If you’re using a button, you can set the onClick event to call this method, and it will allow you to insert a value for the parameter.
You also used the ? operator again in the code, but are still using it incorrectly IDbutton ? 1 : 1
is the same thing as 1