using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class UIChangeLocation : MonoBehaviour { [SerializeField] private Button ShowBtn; [SerializeField] private Button HideBtn; [SerializeField] private Slider Slider; [SerializeField] private Transform Target;//目标 private bool isShow = false; private float canshu = 1; void Start() { RefreshShow(); ShowBtn.onClick.AddListener(()=>{ isShow = true; RefreshShow(); }); HideBtn.onClick.AddListener(() => { isShow = false; RefreshShow(); }); Slider.value = (Slider.minValue + Slider.maxValue) / 2; Slider.onValueChanged.AddListener(ValueChanged); } private void RefreshShow() { ShowBtn.gameObject.SetActive(!isShow); HideBtn.gameObject.SetActive(isShow); Slider.gameObject.SetActive(isShow); } private void ValueChanged(float v) { Target.transform.localScale = Vector3.one * (v) * canshu; } }