#Help with OnClick()
1 messages · Page 1 of 1 (latest)
huh
Your cards can have a script that holds its index. Then you can check if that index is the same as the randomly generated one
Or have a list of those cards in the parent class, and use List.IndexOf to get the index of a certain card in that list
This is a good suggestion, thank you. Would I be able to access the script from that game object by clicking on it? Would I need to add anything other than a GetComponent to access that cards index?
You are using Button, so you can make the onClick trigger a method in the card script
Examples for onClick.AddListener here:
https://docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.Button-onClick.html
You could just add a PickedCorrect and PickedWrong function and then assign those to each card, depending on if its the correct one or not
Would I still be able to assign the correct card as random with that method though?
I don't see why not
I'm having some issues with the implementation of this, as I'm not really sure of how to reference the card that I have clicked. I'm gonna sleep on it and think more about it in the morning. Thank you for your help Osmal
Have the card script on the same object as the button. Add a method like Clicked to the card script. Then in the button's inspector, assign that Clicked method to the button's onClicked
You can do this also with AddListener from a script, but in this case could be easier to just assign it in the inspector