From 7f493f682503f5186308de7b8f74b5b49233cfe4 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 2 Nov 2023 11:51:31 +0800 Subject: +init --- GameCode/Checkbox.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 GameCode/Checkbox.cs (limited to 'GameCode/Checkbox.cs') diff --git a/GameCode/Checkbox.cs b/GameCode/Checkbox.cs new file mode 100644 index 0000000..40e1344 --- /dev/null +++ b/GameCode/Checkbox.cs @@ -0,0 +1,29 @@ +using UnityEngine; +using UnityEngine.Events; + +public class Checkbox : MonoBehaviour +{ + public UnityEvent onToggle = new UnityEvent(); + + public bool state; + + public GameObject checkObj; + + public void SetState(bool active) + { + state = active; + UpdateDisplay(); + } + + public void Toggle() + { + state = !state; + UpdateDisplay(); + onToggle.Invoke(); + } + + private void UpdateDisplay() + { + checkObj.SetActive(state); + } +} -- cgit v1.1-26-g67d0