- 버튼으로 구현한 체크박스
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;
}
}
두개의 이미지를 활용해야하는 체크박스이기 때문에 토글보다 버튼을 활용하여 만드는 것이 효과적이다.
'C# > 수업 과제' 카테고리의 다른 글
재귀함수를 통한 팩토리얼, 피보나치수열 구현 (0) | 2023.02.08 |
---|---|
Unity) [유니티 UI] 팝업 시스템 구현 (0) | 2023.02.07 |
Unity) 유니티 Button.onClick.AddListener 람다식 주의점 (0) | 2023.02.07 |
오브젝트 풀링 (0) | 2023.02.05 |
코루틴, 쓰레드, 프로세스에 대해서 (0) | 2023.02.03 |