ChangeLanguage.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using UnityEngine;
  2. public class ChangeLanguage : MonoBehaviour {
  3. private int lang;
  4. [SerializeField] private GameObject originalSprite;
  5. [SerializeField] private GameObject overSprite;
  6. [SerializeField] private GameObject pressSprite;
  7. [SerializeField] private Sprite[] sprites;
  8. [SerializeField] private Sprite[] overSprites;
  9. [SerializeField] private Sprite[] pressSprites;
  10. private void Start()
  11. {
  12. }
  13. private void Update()
  14. {
  15. lang = PlayerPrefs.GetInt("language"); // Current language
  16. // Set origin sprite
  17. if (originalSprite != null)
  18. {
  19. for (int i = 0; i < sprites.Length; i++)
  20. {
  21. if (lang == i)
  22. {
  23. originalSprite.GetComponent<SpriteRenderer>().sprite = sprites[i];
  24. }
  25. }
  26. }
  27. if (overSprite != null)
  28. {
  29. for (int i = 0; i < overSprites.Length; i++)
  30. {
  31. if (lang == i)
  32. {
  33. overSprite.GetComponent<SpriteRenderer>().sprite = overSprites[i];
  34. }
  35. }
  36. }
  37. // set press button sprite
  38. if (pressSprite != null)
  39. {
  40. for (int i = 0; i < pressSprites.Length; i++)
  41. {
  42. if (lang == i)
  43. {
  44. pressSprite.GetComponent<SpriteRenderer>().sprite = pressSprites[i];
  45. }
  46. }
  47. }
  48. }
  49. }