This may be a silly question to some, one of those in your face obvious and Im hoping that its an easy answer.
Im using Unity onClick with the new UI system. I have the same script on multiple game objects but depending on the state of the game depends on which of those game objects are set active.
So I want a button to only work for the game object that is currently active.
Image is a snap shot of what Im talking about.

The problem I have is that when I click on the button it tries to run the script of the disabled game object and I get an error.
Thanks for your help in advance.
Calling a method on an inactive object shouldn’t throw an error, but depending on what you do inside that method it could throw an error (you should share the script and the exact line that throws the error).
A quick fix would be to see if the gameObject is active at the start of the Check_answer method and return if it’s not:
public void Check_answer(int num) {
if (!gameObject.ActiveInHierarchy)
return;
//your code
}
Anyway, that’s kind of a hack and not a good solution. I would rethink that, you shouldn’t be calling methods that you don’t want to run because it forces you to add checks to early return. Try instead to call only one method in some other class that founds the active “Quizz_scrip” objects and then call the Check_answer method on each of them.