Files
tcg-client/Assets/TcgEngine/Scripts/UI/ToggleText.cs
yaoyanwei 2f2a601227 init
2025-08-04 16:45:48 +08:00

47 lines
975 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TcgEngine;
namespace TcgEngine.UI
{
/// <summary>
/// Changes the color of a unity ui toggle text
/// </summary>
public class ToggleText : MonoBehaviour
{
public Color on_color = Color.yellow;
public Color off_color = Color.white;
private Toggle toggle;
private Text toggle_txt;
private bool previous = false;
void Awake()
{
toggle = GetComponent<Toggle>();
toggle_txt = GetComponentInChildren<Text>();
}
private void Start()
{
Refresh();
}
void Update()
{
if (previous != toggle.isOn)
Refresh();
}
private void Refresh()
{
toggle_txt.color = toggle.isOn ? on_color : off_color;
previous = toggle.isOn;
}
}
}