I am making a Card Game in Which I want to Make a Card Selected when clicked then make only that card selected and highlighted and all the other cards Deselected, everytime a new card is clicked . My aproach is that on the OnPointerClick event I’ll loop trough the scrollView Content panel childs and then change a bool on each of the childrens except for the one clicked to false. I have the following code. but I Do not know how to select each of the childs “Selected” Variable so i can change it. Every card has the same script.
public void OnPointerClick(PointerEventData eventData)
{
for (int i = 0; i < this.transform.parent.childCount; i++)
{
if(this.transform.parent.GetChild(i) != this.transform )
{
// Do not know how to use the "I" to select an specific object variable "Selected".
this.transform.GetChild(i).GetComponent(CardModel).selected = false;
}
}
if (selected)
{
if (cardQuantity > 0)
image.sprite = Faces[1];
else if(cardQuantity == 0)
image.sprite = Faces[3];
}
else if(selected == false)
{
if (cardQuantity > 0)
image.sprite = Faces[0];
else if(cardQuantity == 0)
image.sprite = Faces[2];
}