Hào Vòng
Hào Vòng

Reputation: 1

Can not add click event on gameObject Unity

I want to add a click event on my gameObject, but it won't work, I don't know why it don't work on gameObject, but it work on the test button. I don't know why. Can anybody help me with it. This is the click code:

public void cardsClick()
{
    Debug.Log("aa");
}

And this is how I add click event to game object

enter image description here

Upvotes: 0

Views: 762

Answers (1)

mmarusiak
mmarusiak

Reputation: 57

Buttons Script

I'm not sure where you add the button script. However make sure you add it to Buttton not to Canvas.

Activate Buttons

If you add it correctly I can guess you make this cards inactive before. Then you turn it to active. In this situation Unity is bugged and buttons stop work. Try Button.Interactable instead.

Target graphics

Also if I'm not right try to add target Graphics, because Unity can don't know where is the button.

I don't have more ideas what could went wrong, but I hope I help you.

Upvotes: 0

Related Questions