ToggleTextColor.cs 647 B

12345678910111213141516171819202122232425262728
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class ToggleTextColor : MonoBehaviour
  6. {
  7. [SerializeField] private Color m_ColorUnactive = Color.black;
  8. [SerializeField] private Color m_ColorActive = Color.white;
  9. private Text m_Text = null;
  10. private void Awake() {
  11. if (m_Text == null)
  12. m_Text = GetComponent<Text>();
  13. }
  14. public void SetColor(bool value) {
  15. if (m_Text == null) return;
  16. if (value) {
  17. m_Text.color = m_ColorActive;
  18. }
  19. else {
  20. m_Text.color = m_ColorUnactive;
  21. }
  22. }
  23. }