Good day everyone!
I’m fairly new to Unity and C#, and I’m working on a 2d card memory game. I would like to implement the following:
After the player flips two cards, if they don’t match, then I automatically want them to flip back, without the player having to do it manually.
Is there any way to do this?
I will attach my code below in order for you guys to have a better understanding.
This is my code for where I check if the cards match:
public bool CheckMatch()
{
bool success = false;
if(visibleFaces[0] == visibleFaces[1])
{
visibleFaces[0] = -1;
visibleFaces[1] = -2;
success = true;
ScoreCount.scoreCount += 1;
}
return success;
}
I call this function in another script called FlippingCard:
public void OnMouseDown()
{
if(matched == false)
{
if (spriteRenderer.sprite == back)
{
if (gameControl.GetComponent<MakeVisible>().TwoCardsUp() == false)
{
. . .
matched = gameControl.GetComponent<MakeVisible>().CheckMatch();
}
}
else
{
spriteRenderer.sprite = back;
gameControl.GetComponent<MakeVisible>().RemoveVisibleFace(frontIndex);
}
}
}
I’m assuming that I have to do something in “else” however I can’t seem to figure out what it is.
I’d really appreciate the help!