So when the ball hits the platform, I want the unlockLevel int to equal the scene build index.
Here is my script that defines the int
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
public class ChangeScenes : MonoBehaviour
{
[SerializeField] private string newLevel;
public static int unlockLevel = 0;
public int SceneLoad;
// Start is called before the first frame update
void Start()
{
SceneLoad = SceneManager.GetActiveScene().buildIndex;
Debug.Log(SceneLoad.ToString());
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Goal") {
SceneManager.LoadScene(newLevel);
}
if(SceneLoad == 4)
{
unlockLevel = 4;
Debug.Log("Next Level Unlocked");
}
if (SceneLoad == 5)
{
unlockLevel = 5;
}
if (SceneLoad == 6)
{
unlockLevel = 6;
}
if (SceneLoad == 7)
{
unlockLevel = 7;
}
if (SceneLoad == 8)
{
unlockLevel = 8;
}
if (SceneLoad == 9)
{
unlockLevel = 9;
}
if (SceneLoad == 10)
{
unlockLevel = 10;
}
if (SceneLoad == 11)
{
unlockLevel = 11;
}
if (SceneLoad == 12)
{
unlockLevel = 12;
}
if (SceneLoad == 13)
{
unlockLevel = 13;
}
if (SceneLoad == 14)
{
unlockLevel = 14;
}
if (SceneLoad == 15)
{
unlockLevel = 15;
}
if (SceneLoad == 16)
{
unlockLevel = 16;
}
if (SceneLoad == 17)
{
unlockLevel = 17;
}
}
}
Here is my script that unlocks the level
using System.Collections;
using System.Collections.Generic;
using UnityEditor.iOS;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class UnlockAll : MonoBehaviour
{
public Button button1;
public Button button2;
public Button button3;
public Button button4;
public Button button5;
public Button button6;
public Button button7;
public Button button8;
public Button button9;
public Button button10;
public Button button11;
public InputField input;
public Text text;
public Button button12;
public Button button13;
public string answer;
public ChangeScenes script;
public InputField winText;
public string win = “Demo Reached, More Levels Coming Soon!”;
public Button levelButtons;
public int sceneIndex;
void Start()
{
sceneIndex = SceneManager.GetActiveScene().buildIndex;
Debug.Log(sceneIndex);
}
void Update()
{
answer = input.text;
if ( answer == "UnlockAll" && Input.touchCount>0 || Input.GetKeyDown(KeyCode.Return))
{
button1.interactable = true;
button2.interactable = true;
button3.interactable = true;
button4.interactable = true;
button5.interactable = true;
button6.interactable = true;
button7.interactable = true;
button8.interactable = true;
button9.interactable = true;
button10.interactable = true;
button11.interactable = true;
button12.interactable = true;
button13.interactable = true;
Debug.Log("Levels Enabled");
}
if (ChangeScenes.unlockLevel == 4)
{
button1.interactable = true;
Debug.Log("It Works");
}
}
}