Count keypress(E) on objects/copies

Hi i want to know if/how i can count how many times i have pressed E on objects, after have pressed E 32 times in total, change scene.

I have set up my scene like this

Object A have 7 copies spread all over the scene but the problem is each object have their own counter, i want to have a universal counter that check if i have pressed all E on all the objects 32 times in total and if i have then change scene to my winScene. I have my script on a empty gameobject thats on Object A and the rest of the copies are the same

thanks in advance

Code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

public class Interactable : MonoBehaviour
{
    public GameObject Button;
    public bool isInRange = false;
    public KeyCode interactKey;
    public UnityEvent interactAction;
    int counter = 0;
    public bool hasBeenPressed;
    int keyPressed = 0;
    

    // Start is called before the first frame update
    void Start()
    {
        hasBeenPressed = false;
        isInRange = false;
        counter = 0;
    }

    // Update is called once per frame
    public void Update()
    {
        if (isInRange)
        {       
            if (Input.GetKeyDown(interactKey) && counter < 4)
            {
                Debug.Log("thing");
                counter++;
                hasBeenPressed = true;
                interactAction.Invoke(); Debug.Log("Button Is pressed" + counter);
            }

        }
    }

    private void OnTriggerEnter(Collider collision)
    {
            isInRange = true;
    }

    private void OnTriggerExit(Collider collision)
    {
            isInRange = false;
    }
}

You actually did the hardest part.

The last remaining part to do is:

  1. Create a new script you attach on a dedicated gameObject
  2. Declare an array of Interactable
  3. Listen to the interactAction event of every element of the array
  4. When the event is raised, call a function checking the hasBeenPressed of the interactables. If all are true, change scene

Code not tested

    public Interactable[] Interactables; // Fill inspector
    
    void Start()
    {
        for(int i = 0 ; i < Interactables.Length ; ++i)
             Interatables*.interactAction.addListener(CheckAllPressed);*

}

void CheckAllPressed()

{
for(int i = 0 ; i < Interactables.Length ; ++i)
if(Interatables*.hasBeenPressed ==*
false)
return;
UnityEngine.SceneManagement.SceneManager.LoadScene(“Scene”);
}

Thank You SO MUCH it really helped!!

the only thing i need to do now is change that after i press E 4 times then the bool is true right now its true after the first time i pressed E

If u know quick obvious way that i cannot see to change that in the code feel welcomed to anwser

again Thank you!!

bro it worked, Thank you SO MUCH!!