How to load a new level after the player fixes all the robots in the scene?

I have a level where the player has to throw cogs at some robots to fix them. I want to load the next level as soon as the player fixes all the robots in the scene. I thought about making an int variable counter and adding +1 to the variable in the Fixed() function, and then in Update checking if the counter has reached the number of robots in the scene. But this doesn’t seem to work.

I thought also about making some kind of function that checks if all the robots in the scene are playing the “Fixed” animation. But I have no idea how to do it.

Can anyone help me?
This is my script for the robot:

using UnityEngine;
using UnityEngine.SceneManagement;

public class Enemy : MonoBehaviour
public float speed;
public float timeToChange;
public bool horizontal;

public GameObject smokeParticleEffect;
public ParticleSystem fixedParticleEffect;

public AudioClip hitSound;
public AudioClip fixedSound;

Rigidbody2D rigidbody2d;
float remainingTimeToChange;
Vector2 direction = Vector2.right;
bool repaired = false;

// ===== ANIMATION ========
Animator animator;

// ================= SOUNDS =======================
AudioSource audioSource;

void Start ()
	rigidbody2d = GetComponent<Rigidbody2D>();
	remainingTimeToChange = timeToChange;

	direction = horizontal ? Vector2.right : Vector2.down;

	animator = GetComponent<Animator>();

	audioSource = GetComponent<AudioSource>();

void Update()
	remainingTimeToChange -= Time.deltaTime;

	if (remainingTimeToChange <= 0)
		remainingTimeToChange += timeToChange;
		direction *= -1;
	rigidbody2d.MovePosition(rigidbody2d.position + direction * speed * Time.deltaTime);
	animator.SetFloat("ForwardX", direction.x);
	animator.SetFloat("ForwardY", direction.y);

void OnCollisionStay2D(Collision2D other)
	RubyController controller = other.collider.GetComponent<RubyController>();
	if(controller != null)

public void Fix()
	repaired = true;

	Instantiate(fixedParticleEffect, transform.position + Vector3.up * 0.5f, Quaternion.identity);

	//we don't want that enemy to react to the player or bullet anymore, remove its reigidbody from the simulation
	rigidbody2d.simulated = false;


Use this code to count the number that are not fixed.

You need using System.Linq

FindObjectsOfType<Enemy>().Count((robot) => !robot.fixed && robot.gameobject.isActive);

This will return the number of existing enemies that are active and not fixed.

You could also do this same thing but maintain your own list of active and not fixed enemies in a static variable like this.

static List<Enemy> unfixedRobots = new List<Enemy>();

void OnEnable()

And when it is fixed just call unfixedRobots.Remove(this)

The latter is probably the best solution so you dont have to find then iterate every frame to check you can just use unfixedRobots.Count to check.

Thank you so much for your help!!! It worked! I am still pretty new to Unity and C# and I have a lot to learn.