UIChangeLocation.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class UIChangeLocation : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private Button ShowBtn;
  9. [SerializeField]
  10. private Button HideBtn;
  11. [SerializeField]
  12. private Slider Slider;
  13. [SerializeField]
  14. private Transform Target;//目标
  15. private bool isShow = false;
  16. private float canshu = 1;
  17. void Start()
  18. {
  19. RefreshShow();
  20. ShowBtn.onClick.AddListener(()=>{
  21. isShow = true;
  22. RefreshShow();
  23. });
  24. HideBtn.onClick.AddListener(() => {
  25. isShow = false;
  26. RefreshShow();
  27. });
  28. Slider.value = (Slider.minValue + Slider.maxValue) / 2;
  29. Slider.onValueChanged.AddListener(ValueChanged);
  30. }
  31. private void RefreshShow()
  32. {
  33. ShowBtn.gameObject.SetActive(!isShow);
  34. HideBtn.gameObject.SetActive(isShow);
  35. Slider.gameObject.SetActive(isShow);
  36. }
  37. private void ValueChanged(float v)
  38. {
  39. Target.transform.localScale = Vector3.one * (v) * canshu;
  40. }
  41. }