Enable prefabs in different scene on level load

Hi guys,

I am making a 2D game and have 3 scenes. First is menu. Second is levels. Third is level 1. I have one level in the levels scene that is interactable. The rest are not interactable. I wrote a script for when level 1 is loaded the 2nd level in the levels scene is interactable unlocking the level. The problem is when i test this and load level 1 and go back to the levels scene the level 2 button is still not interactable. I attached the script to my camera in level 1 and used the button prefab for the script. But still nothing works.

Script

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class LevelUnlocker : MonoBehaviour {

public int scenes;
public Button level;

void OnLevelWasLoaded(int scene) {
	if (scene == scenes)
		level.interactable = true;
	
}
  }

If you want to persist data across scenes, you could try PlayerPrefs. GameObjects are thrown away when you leave the scene they originated from, so you can’t use them like this.

You need to use the DontDestroyOnLoad(); function.

It allows gameobjects to persist between scenes.

A good live training session on explaining this can be found here:

https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/creating-a-scene-menu