using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
public class DictatorTeleport : MonoBehaviour
{
void OnGUI()
{
SceneManager.LoadScene("CityScene", LoadSceneMode.Additive);
SceneManager.SetActiveScene(SceneManager.GetSceneByName("CityScene"));
}
}
This doesn’t work. How would I make it change to my other scene called “CityScene” on GUI button click?
Scene ‘CityScene’ (-1) couldn’t be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
ArgumentException: SceneManager.SetActiveScene failed; invalid scene
UnityEngine.SceneManagement.SceneManager.SetActiveScene (Scene scene)
What he mean here is that OnGUI() is used for the legacy UI system where you would manually create a button within code. for the new system you should simply use a Public function and attach it to the OnClick() option on the button.
Alright, thanks. That makes sense. But how would I make an Interactable function from in here? I don’t see any option that lets me create an Interactable function, like how I can make a SetActive function. Sorry to answer answers with more questions. See image below.
I dont know exactly what you are doing with those scipts on the OnClick() but if you want to make it so that a button cannot be interacted with simply do:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ForumTest : MonoBehaviour
{
// A reference to the button
public Button test;
void Update ()
{
// What will trigger this?
// EDIT THIS!
if(conditionIsMet = true)
{
// If the condition is met than set the button to be interactable!
// Easy!
test.interactable = true;
}
}
}