Making a button disappear in a specific language

More
7 years 3 months ago #2413 by jimmyt3d
Hi Frank,

I have a button that I don't want to appear when a specific language is selected.
I have currently set this up by doing the following -

- Make an invisible version of the button (just an empty image)
- Set the button's text to '---' so that it doesn't appear

The only problem with this is that if you click the area where the button is, it will still 'click' even though you can't see it.

Is there a way of turning it off/set to not interactive when the specific language is selected?
Note - The button is NOT in the same scene as the language select screen.

Please Log in or Create an account to join the conversation.

More
7 years 3 months ago #2414 by Frank
Hi,
The easiest way to implement that is to make a script that show/hide the button whenever there is a localization:

Just attach this script to your button and select the languages that should hide the button:

Assets/HideOnLanguages.cs
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;

namespace I2.Loc
{
    public class HideOnLanguages : MonoBehaviour
    {
        public List<string> _Languages = new List<string>();

        public void Start()
        {
            LocalizationManager.OnLocalizeEvent += OnLocalize;
            OnLocalize();
        }

        public void OnDestroy()
        {
            LocalizationManager.OnLocalizeEvent -= OnLocalize;
        }
        public void OnLocalize()
        {
            var currentLanguage = LocalizationManager.CurrentLanguage;
            var show = !_Languages.Contains(currentLanguage);

            gameObject.SetActive(show);
        }
    }
}

Whenever the language changes, or the screen is opened, this script will be executed and it will hide the object if the language is in that list.

Hope that helps,
Frank

Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out
The following user(s) said Thank You: jimmyt3d

Please Log in or Create an account to join the conversation.

More
7 years 3 months ago #2415 by jimmyt3d
Hi Frank,

Many thanks for this, it works a treat!

Note to anyone else using this - in the editor it is only visible happening by pressing play first (rather than clicking through the languages in the inspector).

Thanks again

Please Log in or Create an account to join the conversation.

Time to create page: 0.212 seconds
Template by JoomlaShine