using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class SliderList : MonoBehaviour
{
[SerializeField] Image imageOn;
[SerializeField] Image imageOff;
[SerializeField] Slider slider;
[SerializeField] int sliderValue;
[SerializeField] TMP_Text curruntText;
[SerializeField] TMP_Text MaxText;
void Start()
{
this.slider.value = sliderValue;
ImageState();
StartCoroutine(UpdateState());
}
IEnumerator UpdateState()
{
while (true)
{
curruntText.text = Convert.ToString(slider.value);
if(slider.value > 0)
{
curruntText.color = new Color32(250, 176, 55, 255);
ImageState();
}
else
{
curruntText.color = new Color32(118, 97, 125, 255);
ImageState();
}
yield return null;
}
}
private void ImageState()
{
if(slider.value > 0)
{
imageOn.gameObject.SetActive(true);
imageOff.gameObject.SetActive(false);
}
else
{
imageOn.gameObject.SetActive(false);
imageOff.gameObject.SetActive(true);
}
}
}
4. SliderList.cs (Slider)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ToggleList : MonoBehaviour
{
[SerializeField] private GameObject imageOn;
[SerializeField] private GameObject imageOff;
[SerializeField] private Button toggleBtn;
[SerializeField ]private bool isImage = true;
void Start()
{
UpdateImage();
this.toggleBtn.onClick.AddListener(() => {
if(isImage)
{
isImage = false;
}
else
{
isImage = true;
}
UpdateImage();
});
}
private void UpdateImage()
{
if(isImage)
{
this.imageOn.gameObject.SetActive(true);
this.imageOff.gameObject.SetActive(false);
}
else
{
this.imageOn.gameObject.SetActive(false);
this.imageOff.gameObject.SetActive(true);
}
}
}
5. ToggleList.cs (Toggle)
'산대특 > 게임 UIUX프로그래밍' 카테고리의 다른 글
[LearnUGUI] Start 버튼 클릭 시 씬 전환 + 캐릭터 이동 (0) | 2024.02.10 |
---|---|
[LearnUGUI] Home 화면에서 광고 버튼 누르면 Popup 보여주기 (0) | 2024.02.10 |
[LearnUGUI] ShopChest 동적 스크롤 뷰 + 데이터 연동 구현 (0) | 2024.02.08 |
[LearnUGUI] 상자 이미지 변경하기 (0) | 2024.02.08 |
[LearnUGUI] 스킬 버튼 만들기 (+쿨타임) (0) | 2024.02.08 |