So the first script is my c# that have control and the seccond c# is my enemy script where id does this :
Application.LoadLevel("TestLevel1");```
So my question is how can i do it good. Because now if i select Level1 for example and if Level2 is unlocked it unlocks Level3 and i don't wand that i wand if i play thro Level1 > Level5 That when i join a older level for example Level4 Level6 does not unlock. I now the +1 Means unlock 1 level even if i play for example level3 and then Level6 unlocks
```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LevelManager1 : MonoBehaviour
{
Button[] LevelButons;
// Start is called before the first frame update
private void Awake()
{
int ReachedLevel = PlayerPrefs.GetInt("ReachedLevel", 1);
if (PlayerPrefs.GetInt("Level") >= 2)
{
ReachedLevel = PlayerPrefs.GetInt("Level");
}
LevelButons = new Button[transform.childCount];
for (int i = 0; i < LevelButons.Length; i++)
{
LevelButons[i] = transform.GetChild(i).GetComponent<Button>();
LevelButons[i].GetComponentInChildren<Text>().text = (i + 1).ToString();
if (i + 1 > ReachedLevel)
{
LevelButons[i].interactable = false;
}
}
}
//loads all levels but you have to chanche the name from LoadLevel!
public void LoadScene1(int Level)
{
PlayerPrefs.SetInt("Level", Level);
Application.LoadLevel("Level1");
}
public void LoadScene2(int Level)
{
PlayerPrefs.SetInt("Level", Level);
Application.LoadLevel("Level2");
}
public void LoadScene3(int Level)
{
PlayerPrefs.SetInt("Level", Level);
Application.LoadLevel("Level3");
}
public void LoadScene4(int Level)
{
PlayerPrefs.SetInt("Level", Level);
Application.LoadLevel("Level4");
}
public void LoadScene5(int Level)
{
PlayerPrefs.SetInt("Level", Level);
Application.LoadLevel("Level5");
}
void Update()
{
}
}
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
public class LevelController : MonoBehaviour
{
private Enemy[] _enemies;
private void OnEnable()
{
_enemies = FindObjectsOfType<Enemy>();
}
// Update is called once per frame
void Update()
{
foreach(Enemy enemy in _enemies)
{
if (enemy != null)
return;
}
Debug.Log("you killed all enemies");
PlayerPrefs.SetInt("ReachedLevel", PlayerPrefs.GetInt("ReachedLevel") + 1);
Application.LoadLevel("TestLevel1");
}
}