using UnityEngine; using UnityEngine.Localization; using UnityEngine.Localization.Settings; using TMPro; public class LanguageDropdown : MonoBehaviour { public GameObject languageDropdownObject; // Dropdown container public TMP_Dropdown languageDropdown; // TMP Dropdown // List of language codes in the same order as the Dropdown options private readonly string[] languageCodes = { "en", "zh-Hans", "ru", "es", "pt-BR", "de", "ko", "fr", "ja", "pl", "zh-Hant", "it", "th", "el", "tr", "nl", "hi", "id", "sv", "uk", "vi" }; void Start() { languageDropdown.ClearOptions(); languageDropdown.AddOptions(new System.Collections.Generic.List { "English", "中文", "Русский", "Español", "Português", "Deutsch", "한국어", "Français", "日本語", "Polski", "中文 (繁體)", "Italiano", "ไทย", "Ελληνικά", "Türkçe", "Nederlands", "हिन्दी", "Bahasa Indonesia", "Svenska", "Українська", "Tiếng Việt" }); // Set currently selected locale var currentCode = LocalizationSettings.SelectedLocale.Identifier.Code; int index = System.Array.IndexOf(languageCodes, currentCode); if (index >= 0) languageDropdown.value = index; } public void OnLanguageChanged(int index) { if (index < 0 || index >= languageCodes.Length) return; var selectedCode = languageCodes[index]; var selectedLocale = LocalizationSettings.AvailableLocales.Locales.Find(l => l.Identifier.Code == selectedCode); if (selectedLocale != null) { LocalizationSettings.SelectedLocale = selectedLocale; Debug.Log("Language changed to: " + selectedCode); } } }