101won 2024. 8. 30. 00:50

클릭하면 체크가 나타났다 사라졌다...

 

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting.Antlr3.Runtime.Tree;
using UnityEngine;
using UnityEngine.UI;

public class ToggleController : MonoBehaviour
{
    // 체크 박스
    public Button chackBox;
    public GameObject OnBox;

    bool isOn; 

    void Start()
    {
      // 디폴트: OFF
        this.chackBox.onClick.AddListener(() => {

            if (isOn == false) 
            {
                Debug.Log("껴져있길래 켰어");

                OnBox.SetActive(true); // 게임 오브젝트 보이기
                isOn = true; // 버튼 bool 상태 변경
            }
            else
            {
                Debug.Log("켜있길래 껐어");

                OnBox.SetActive(false); // 게임 오브젝트 안보이기
                isOn = false; // 버튼 bool 상태 변경
            }
        });
    }
}

 

 

empty UICheckBox
 - bg(최하단에 깔아놓음)
 - On(이미지 클릭하면 사라짐)
 - Button