Forum rules - please read before posting.

language setting saved on restart

Hi Chris,

I have a script in AC for PS5 where I need the game to remember the language setting saved on restart, I have this script in first scene as a game object, but it doesn't seem to work:

using UnityEngine;
using AC;

public class SetLanguageBasedOnSystem : MonoBehaviour
{
    private void Start()
    {
        // Get the system language
        SystemLanguage systemLanguage = Application.systemLanguage;

        // Map SystemLanguage to AC language index
        int languageIndex = GetLanguageIndex(systemLanguage);

        // Set the language in Adventure Creator
        if (languageIndex >= 0 && languageIndex < KickStarter.speechManager.Languages.Count)
        {
            Options.SetLanguage(languageIndex);
            Debug.Log("Language set to: " + KickStarter.speechManager.Languages[languageIndex]);
        }
        else
        {
            Debug.LogWarning("System language not supported, using default language.");
        }
    }

    private int GetLanguageIndex(SystemLanguage systemLanguage)
    {
        // Map Unity's SystemLanguage to AC language indices
        switch (systemLanguage)
        {
            case SystemLanguage.English: return 0; // Example: English is the first language
            case SystemLanguage.French: return 1;  // Example: French is the second language
            case SystemLanguage.Spanish: return 2; // Example: Spanish is the third language
            // Add more cases as needed
            default: return -1; // Return -1 if the language is not supported
        }
    }
}

Comments

  • What do the logs say? Don't print Languages[languageIndex] - instead just print the index.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.