using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; using UnityEngine.EventSystems; using UnityEngine.SceneManagement; public class ButtonScript : MonoBehaviour { [SerializeField] Button button; [SerializeField] Text text; [SerializeField] GUISkin skin; [SerializeField] InputField input; [SerializeField] Image image; [SerializeField] RawImage rawImage; [SerializeField] EventSystem ec; [SerializeField] UnityEngine.UIElements.ScrollView scroll; private string btnText = "This is a button"; // Start is called before the first frame update private void OnGUI() { //GUI.skin = skin; GUI.Label(new Rect(0, 0, 200, 100), "Hi - I'm a label looking like a box", "box"); // 创建使用"“切换键" GUIStyle 的按钮 if (Time.time % 2 < 1 && GUI.Button(new Rect(10, 140, 180, 20), btnText)) { btnText = "hello world" + Time.time; } GUI.Button(new Rect(100, 100, 300, 30), "Skinned Button"); } void Start() { var a = GameObject.Find("ViewportGrid"); Debug.Log($"{Screen.width},{Screen.height}"); Debug.Log(gameObject.name); button.onClick.AddListener(() => { if (SceneManager.GetActiveScene().name == "Demo1") { SceneManager.LoadScene("Demo2"); } else { SceneManager.LoadScene("Demo1"); } }); input.onEndEdit.AddListener((t)=> { Debug.Log(t); text.text = t; }); //image.flexibleWidth = Screen.width; //image.flexibleHeight = Screen.height; } // Update is called once per frame void Update() { } void OnDestroy() { button.onClick.RemoveAllListeners(); input.onEndEdit.RemoveAllListeners(); } }