- Home /
The question is answered, right answer was accepted
Help with level unlock sysyem
so I tried to make a level unlock system that uses ints and I thought it would work but it says "NullReferenceException: Object reference not set to an instance of an object finish.Start () (at Assets/Scripts/finish.cs:42)"
What I did is in the code below and the script is on my finish trigger and my canvas in my level selector.
I created public buttons and assigned all of them on my level selector but when I go back to level 1 it has all of the slots like I thought. When I hit play it said that error up above. I did not set any of the buttons slots on the inspector to anything because I did not have anything to put on it. and some of the code will have my finish trigger stuff in it. HELP!! EDIT:I have filled all of the buttons with buttons that are turned off but when i complete a level and go back to a menu it still doesn't have level 2 unlocked. NEED BIG HELP!!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class finish : MonoBehaviour {
public int scene = 1;
public int unlockedlevel = 0;
public GameObject LevelComplete;
public Button button2;
public Button button3;
public Button button4;
public Button button5;
public Button button6;
public Button button7;
public Button button8;
private void OnTriggerEnter()
{
LevelComplete.SetActive(true);
if( scene >= unlockedlevel)
{
unlockedlevel = unlockedlevel + 2;
}
}
private void Start()
{
button2.interactable = false;
button3.interactable = false;
button4.interactable = false;
button5.interactable = false;
button6.interactable = false;
button7.interactable = false;
button8.interactable = false;
Invoke("Unlocked", 2f);
}
public void Unlocked ()
{
if(unlockedlevel >= scene)
{
button2.interactable = true;
}
}
}
This is my level 1 Trigger inspector:
Answer by tormentoarmagedoom · May 09, 2018 at 09:58 PM
Good day.
First, read some questions before coming to ask. and try to find the answer in the forums.
Second, If want help, help us by explaining what you need, what you have, and what you tried before coming to ask for help.
Third, please remake the question giving more information, showing some screenshot to help people give you a correct answer.
Good day again.
I think you need a very basic learning.... You are not traspassing information between scenes. When you change scene, all from last scene is destroyed, and instantiated all new scene as new.
Go learn the first part of this Unity tutorial about SAve data between scenes
Bye.
Thanks, I looked up some and I found out that you can use ints so I tried to do it and it did not go so well so if you can take a look at it that would be great!