Welcome, Guest
Username: Password: Remember me

TOPIC: Making a button disappear in a specific language

Making a button disappear in a specific language 2 months 3 weeks ago #2413

  • jimmyt3d
  • jimmyt3d's Avatar
  • Offline
  • Senior Member
  • Posts: 43
  • Thank you received: 1
  • Karma: 1
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.
The administrator has disabled public write access.

Making a button disappear in a specific language 2 months 3 weeks ago #2414

  • Frank
  • Frank's Avatar
  • Offline
  • Administrator
  • Posts: 897
  • Thank you received: 193
  • Karma: 57
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 administrator has disabled public write access.
The following user(s) said Thank You: jimmyt3d

Making a button disappear in a specific language 2 months 3 weeks ago #2415

  • jimmyt3d
  • jimmyt3d's Avatar
  • Offline
  • Senior Member
  • Posts: 43
  • Thank you received: 1
  • Karma: 1
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
The administrator has disabled public write access.
Time to create page: 0.127 seconds
Colors