How to make a WinText after killing the last enemy?

I have several objects (any number).

After destroying everyone in the right order (e.g 1-4) should appear: “YouWin”.

Unfortunately, I do not know how to creating a method on a central square, when a correct square (LAST SQUARE) is destroyed.

The central object would have to know the last number (or total number needed to win).

Could someone help you?

Script in my central object:

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

public class Gamer : MonoBehaviour {

	int index =1;
	public GameObject gameOverText, restartButton ;

	public GameObject WinningText, ExitButton, NextLevelButton ;

	public GameObject Manager;


	void Start () {
		gameOverText.SetActive (false);
		restartButton.SetActive (false);
		Manager.SetActive (true);
		WinningText.SetActive (false);
		ExitButton.SetActive (false);
		NextLevelButton.SetActive (false);
	}
    
	public void OnCollisionEnter2D (Collision2D col)
	{
		Debug.Log("Player hit object: " + col.transform.name);
		//check if the object you hit is one of the "collisionObjects":
		if(col.transform.GetComponent<collisionObject>())
		{
			collisionObject colObj = col.transform.GetComponent<collisionObject>();
			if(!colObj) return;
			if(index == colObj.myIndexNumber) {
				Destroy(col.gameObject);
				index++;
   			}
			// here, we know it didn't match the number. :)
			else  {
				gameOverText.SetActive (true);
				restartButton.SetActive (true);
				gameObject.SetActive (false);
				Manager.SetActive (false);

			}
    				}	
    			}
		}

Script on the destroyed object:

		public int myIndexNumber;

		public void Start()
		{
			Debug.Log("Object number " + myIndexNumber + " is here");
		}
}

With this you should be good to go:

public void OnCollisionEnter2D (Collision2D col)
	{
		Debug.Log("Player hit object: " + col.transform.name);
		//check if the object you hit is one of the "collisionObjects":
		if(col.transform.GetComponent<collisionObject>())
		{
			collisionObject colObj = col.transform.GetComponent<collisionObject>();
			if(!colObj) return;
			if(index == colObj.myIndexNumber) {
				if (colObj.isHighestNumber) {
					Debug.Log ("Yay you correctly hit the last Square, You WIN!");
					WinningText.SetActive (true);
					restartButton.SetActive (true);
					gameObject.SetActive (false);
					Manager.SetActive (false);
				}
				Destroy(col.gameObject);
				index++;

			}
			// here, we know it didn't match the number. :)
			else  {
				gameOverText.SetActive (true);
				restartButton.SetActive (true);
				gameObject.SetActive (false);
				Manager.SetActive (false);

			}
		}    
	}






	public int myIndexNumber;
	public bool isHighestNumber;
	public void Start()
	{
		
		isHighestNumber = true;
		//find all other objects:
		foreach (collisionObject cObj in GameObject.FindObjectsOfType<collisionObject>()) {
                   //check if any of the other objects has a larger number than mine, if yes, note to self that i am not the highest number.
			if (cObj.myIndexNumber > myIndexNumber) {
				isHighestNumber = false;
				break;
			}
		}
		Debug.Log("Object number " + myIndexNumber + " is here // is highest Number: " + isHighestNumber);
	}

I only edited your OnCOllisionEnter function, and the collisionObject class, exchange that code. If something is unclear go ahead an ask.

In case you ever come across of a whole lot of squares like 100+ you should think of a smarter way to check for the highest number since this code should work but will not be efficient for a huge amount of objects.

Have an integer that starts at the number of enemies and goes down each time an enemy is killed. After each enemy is killed, check if the counter is zero. If it is zero then all the enemies have been killed and you can make “you win!” appear.

use this

  void Update(){
            if(!GameObject.FindGameObjectWithTag"Enemy")
            {
                             gameOverText.SetActive (true);
                             restartButton.SetActive (true);
                             gameObject.SetActive (false);
                             Manager.SetActive (false);
            }
    }

or this

      void Update () {
                    GameObject[]  enemies;
                    enemies = GameObject.FindGameObjectsWithTag("Enemy");
                
                    if (enemies.length == 0) {
                
                               gameOverText.SetActive (true);
                              restartButton.SetActive (true);
                              gameObject.SetActive (false);
                              Manager.SetActive (false);
                    }
                }