12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 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;
- }
- }
|