1. Setting의 구조

 

2. 실행 이미지

 

3. 실행 이미지

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)

+ Recent posts