using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /// <summary> /// /// </summary> public class EventBtn : MonoBehaviour { public Transform PanelBg; public Button UpBtn; public Button DownBtn; private float PanelHeight; //public Transform ControlPanel; void Awake() { PanelHeight = PanelBg.GetComponent<Collider>().bounds.size.y; Debug.Log(PanelHeight); } void Start () { } void Update () { UpBtn.onClick.AddListener(delegate () { this.OnClickEvent(true); }); DownBtn.onClick.AddListener(delegate () { this.OnClickEvent(false); }); } public void UpBtnEvent() { UpBtn.transform.localScale = Vector3.zero; Vector3 newPos = new Vector3(transform.position.x, transform.position.y + PanelHeight, transform.position.z); PanelBg.transform.position = Vector3.Slerp(transform.position, newPos, 3); DownBtn.transform.localScale = Vector3.one; } public void DownBtnEvent() { DownBtn.transform.localScale = Vector3.zero; Vector3 newPos = new Vector3(transform.position.x, transform.position.y - PanelHeight, transform.position.z); PanelBg.transform.position = Vector3.Slerp(transform.position, newPos, 3); UpBtn.transform.localScale = Vector3.one; } public void OnClickEvent(bool trueOrFalse) { switch (trueOrFalse) { case true: UpBtn.transform.localScale = Vector3.zero; Vector3 newPos = new Vector3(transform.position.x, transform.position.y + PanelHeight, transform.position.z); PanelBg.transform.position = Vector3.Slerp(transform.position, newPos, 3); DownBtn.transform.localScale = Vector3.one; break; case false: DownBtn.transform.localScale = Vector3.zero; Vector3 newPos0 = new Vector3(transform.position.x, transform.position.y - PanelHeight, transform.position.z); PanelBg.transform.position = Vector3.Slerp(transform.position, newPos0, 3); UpBtn.transform.localScale = Vector3.one; break; } } }
原文:https://www.cnblogs.com/allyh/p/11456377.html