ButtonLocalization.cs 777 B

1234567891011121314151617181920212223
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. [RequireComponent(typeof(Button))]
  5. public class ButtonLocalization : MonoBehaviour
  6. {
  7. public string key;
  8. void Start() {
  9. // Get the string value from localization manager from key
  10. // and set the text component text value to the returned string value
  11. string text = LocalizationManager.Instance.GetText(key);
  12. text = text.Replace("\\n", Environment.NewLine);
  13. GetComponent<Button>().GetComponentInChildren<Text>().text = text;
  14. }
  15. internal void UpdateText() {
  16. string text = LocalizationManager.Instance.GetText(key);
  17. text = text.Replace("\\n", Environment.NewLine);
  18. GetComponent<Button>().GetComponentInChildren<Text>().text = text;
  19. }
  20. }