How to automatically flip the cards back when they don't match

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!

Yes of course you would do something if they’re not “matched”. Are you keeping a reference to the cards the player interacts with? Having those you just need to call a function that “flips card back” passing those two cards as argument. Honestly not being able to see what you coded entirely makes it hard to give you a personal answer, as there are many ways you could achieve this.

You may find this helpful in the long run

What you need to do is iterate the existing cards. You will need to have stored them somewhere that the objects can be accessed, like a Stack<GameObject> or List<GameObject> for example.

See also: https://www.w3schools.com/cs/cs_data_types.asp

But you could just change every card position to a Vector3 normal which represents the un-flipped cardinality, no pun intended, such as transform.rotation to Vector3.Forward, or Quaternion.identity, in script-like code.

Gods, I hate this editor.