Hello!
I want to open a new scene on click of a button and I wrote the following script:
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEditor.SceneManagement;
public class HomeButtonController : MonoBehaviour {
string level = "1stQuestion";
public Button Button;
Button button = Button.GetComponent<Button>();
public void buttonController() {
EditorSceneManager.OpenScene(level);
}
void Update () {
button.onClick.AddListener(buttonController);
}
}
But unity throws me Error CS0236: A field initializer cannot reference the nonstatic field, method, or property `HomeButtonController.Button’ … Any suggestions please?