using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ToggleScript : MonoBehaviour { public GameObject[] tog; int mouseY_; int curMouseY_; bool defTog; // Start is called before the first frame update void Start() { OnTog0(); } public void OnClick() { if (tog.Length < 3) { OnTog2(); } else { OnTog0(); } } void OnTog0() { tog[0].SetActive(true); defTog = true; for (int i = 1; i < tog.Length; i++) { tog[i].SetActive(false); } } void OnTog2() { for (int i = 0; i < tog.Length; i++) { if (tog[i].activeSelf == true) { tog[i].SetActive(false); } else { tog[i].SetActive(true); } } } public void OnMouseDown() { mouseY_ = (int)Input.mousePosition.y; //Debug.Log($"mouseY {mouseY_}"); } public void OnMouseUp() { curMouseY_ = (int)Input.mousePosition.y; if (curMouseY_ != mouseY_) { //Debug.Log($"curMouseY {curMouseY_}"); int dMY = mouseY_ - curMouseY_; if (tog.Length < 3) { OnTog2(); } else { if(defTog == true) { defTog = false; if (dMY < 0) { tog[0].SetActive(false); tog[1].SetActive(true); tog[2].SetActive(false); } else { tog[0].SetActive(false); tog[1].SetActive(false); tog[2].SetActive(true); } } else { OnTog0(); } } } } }