- 버튼으로 구현한 체크박스

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class UICheckBox : MonoBehaviour
{
    public Button checkBtn;
    public GameObject onCheckBtn;
    private bool isOn;

    void Start()
    {
        this.checkBtn.onClick.AddListener(() =>
        {
            if(isOn == false)
            {
                this.OnCheckBox();
                Debug.Log("CheckBoxOn");                
            }
            else
            {
                this.OffCheckBox();
                Debug.Log("CheckBoxOff");                
            }
        });
    }

    public void OnCheckBox()
    {
        this.onCheckBtn.SetActive(true);
        this.isOn = true;
    }

    public void OffCheckBox()
    {
        this.onCheckBtn.SetActive(false);
        this.isOn = false;
    }
}

두개의 이미지를 활용해야하는 체크박스이기 때문에 토글보다 버튼을 활용하여 만드는 것이 효과적이다.

 

클릭으로 작동하는 체크박스

 

 

+ Recent posts