using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class qiehuanScenes : MonoBehaviour { [Header("按钮,请一一对应")] public Button btn1; public Button btn2; public Button btn3; public Button btn4; public Button btn5; [Header("对应的场景")] public GameObject scene1; public GameObject scene2; public GameObject scene3; public GameObject scene4; public GameObject scene5; [Header("当前场景")] public GameObject nowScene; // Start is called before the first frame update void Awake() { btn1.onClick.AddListener(()=> { if (scene1== nowScene) { return; } scene1.SetActive(true); this.nowScene.SetActive(false); }); btn2.onClick.AddListener(()=> { if (scene2 == nowScene) { return; } scene2.SetActive(true); this.nowScene.SetActive(false); }); btn3.onClick.AddListener(()=> { if (scene3 == nowScene) { return; } scene3.SetActive(true); this.nowScene.SetActive(false); }); btn4.onClick.AddListener(()=> { if (scene4 == nowScene) { return; } scene4.SetActive(true); this.nowScene.SetActive(false); }); btn5.onClick.AddListener(()=> { if (scene5 == nowScene) { return; } scene5.SetActive(true); this.nowScene.SetActive(false); }); } }