0

enter image description here enter image description here

enter code here

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using static extensionMethods;

[RequireComponent(typeof(Dropdown))]
public class ChangeLanguage : MonoBehaviour
{
    private LocalizationManager localizationManager;
    void Start()
    {
       
    }
     public void changeLanguage(int num)
     {
         Debug.Log(num);
         localizationManager = LocalizationManager.instance;
         string Langunage = "";
         if (num == 0)
             Langunage = "TM";
         if (num == 1)
             Langunage = "RU";
         if (num == 2)
             Langunage = "EN";
         if (num == 3)
             Langunage = "KZ";
         if (num == 4)
           Langunage = "TR";
        localizationManager.SetLanguage(Langunage);
        SceneManager.LoadScene("Loading");
     } 
   

}

After Choosing Language By DropDown I'am doing ReloadScene Language is translated but value of option DropDown is not Changed Can you help me to resolve that Problem

  • Please pay close attention to the tags you select, so you don't select the wrong ones by mistake (like selecting the C language tag instead of C#). – Some programmer dude Apr 01 '21 at 10:28

1 Answers1

0

This is because when the scene is reloaded, the dropdown is set to their default values again (the ones you set to it before hitting "play").

You need to set the value yourself using the saved current language in the localizationManager. If you're not saving it, then you will have to save it there, so you can do as I said, set the dropdown value again when the scene reloads.

It can be done in that same script just add it to Start() method, or even Awake().

Edit.- Let's say you saved the language in a similarly called "langunage" variable in localizationManager. Now in Start() you set the dropdown to that "langunage" string. You can do so by also saving the index in, for example and int variable called langindex, and then using the mydropdown.value = langindex;

Beware tho, using the .value field will recall the OnValueChanged event which is your changeLanguage(int) Method, thus reloading the Scene again and again and again. You should consider other ways of updating the language without reloading the scene.

Daahrien
  • 10,190
  • 6
  • 39
  • 71