How do i change this so that if i collect the objects out of order the scene resets?

using UnityEngine;
using System.Collections;

public class CollectInOrder : MonoBehaviour {

public float collectNumber;
public int collectLimit;

void OnTriggerEnter2D(Collider2D coll){
	if ( == "Collect" + collectNumber) { 
		Destroy (coll.gameObject);
		if (collectNumber >= collectLimit) { 
			ResetCollectNumber ();

public void ResetCollectNumber(){
collectNumber = 1;


Each object would need to have a reference to the next one which should be picked up. If the picked up object isn’t the one which was needed, reset the scene.

Also you aren’t setting collectNumber to 1 at the start (you provide no default value) so maybe doing that will solve your problem.