Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by K4nickel · Nov 21, 2017 at 10:11 PM · variablesgameobjects

GameObject[0].SetActive (false); more than one GamObject possible?

I want to make a game in 2 different languages, i had an idea how to do it but there are too many texts to write it like this: englishTexts[0].SetActive (true); germanTexts[0].SetActive (false);
englishTexts[1].SetActive (true); germanTexts[1].SetActive (false); ..... and it goes on like this, i already have 15 Texts and there are coming more. So it is possible to somehow put multiple Objects (Texts) in one? Example: englishTexts[0, 1, 2].SetActive (true); Hope you can help, thanks public GameObject mainMenuHolder; public GameObject achievementsMenuHolder; public GameObject optionsMenuHolder; public GameObject languagesHolder; public GameObject[] englishTexts; public GameObject[] germanTexts;

     void Update() {
         
         if (PlayerPrefs.GetString("english") == "true") {
             englishTexts[0].SetActive (true);
             germanTexts[0].SetActive (false);
         }
     
         if (PlayerPrefs.GetString("german") == "true") {
             englishTexts[0].SetActive (false);
             germanTexts[0].SetActive (true);
         }
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Nov 21, 2017 at 11:13 PM

Just use a loop. Also it makes no sense to use two seperate player prefs for choosing the language. It makes more sense to use a "language" string and set it to the language you want.


In addition you shouldn't execute this every frame. Using a seperate method to update the language would make more sense. Call it once in Start and whenever you actually changed the language

 void UpdateTexts()
 {
     string lang = PlayerPrefs.GetString("language");
     for(int i = 0; i < englishTexts.Length; i++)
     {
         englishTexts[i].SetActive (lang == "english");
         germanTexts[i].SetActive (lang == "german");    
     }
 }

This will enable all english texts when "lang" is "english" and also disable all the german texts. This of course assumes that you have the same amount of texts in each array. If for some reason you don't have the same amount you need to use seperate loops


 void UpdateTexts()
 {
     string lang = PlayerPrefs.GetString("language");
     for(int i = 0; i < englishTexts.Length; i++)
     {
         englishTexts[i].SetActive (lang == "english");
     }
     for(int i = 0; i < germanTexts.Length; i++)
     {
         germanTexts[i].SetActive (lang == "german");    
     }
 }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image K4nickel · Nov 23, 2017 at 05:56 PM 0
Share

Thanks for your answer, this is exactly what i need. I will try it out when i have time in a few hours

avatar image K4nickel · Nov 23, 2017 at 07:06 PM 0
Share

If i put in "void UpdateTexts" it doesn't work, if i change it to "void Update" it does work. Could you explain me what's the difference? :/

avatar image Bunny83 K4nickel · Nov 23, 2017 at 11:11 PM 0
Share

Have you missed this paragraph in my answer:

In addition you shouldn't execute this every frame. Using a seperate method to update the language would make more sense. Call it once in Start and whenever you actually changed the language

avatar image K4nickel · Nov 23, 2017 at 07:12 PM 0
Share

Okay so i changed your script a little bit and now it works perfectly and it's easy to reconstruct. Thank you for the help

avatar image
0

Answer by voncarp · Nov 21, 2017 at 11:09 PM

If you want to hardcode it in, something like this works if you can follow it. You just send the string from the text. And if it matches and you have your preferred language selected it should return the translated value. You might need to mod it a bit to get what you want.

 using UnityEngine;
 
 public class localize : MonoBehaviour {
     
     public enum language {
         english,
         vietnamese
     }
 
     public language currentLanguage;
     public static language l;
 
     void Awake() {
         switch (currentLanguage) {
         case language.english:
             l = language.english;
             break;
         case language.vietnamese:
             l = language.vietnamese;
              break;
         }
     }
 
     public static string translate (string txt) {
         switch (txt) {
         case "PICK UP ":
             switch (l) {
             case language.english:
                 txt = "PICK UP ";
                 break;
             case language.vietnamese:
                 txt = "chọn ";
                  break;
             }
              break;
         case "WATER BAG":
             switch (l) {
             case language.english:
                 txt = "WATER BAG";
                 break;
             case language.vietnamese:
                 txt = "Túi nước";
                 break;
             }
             break;
         }
         return txt.ToUpper();
     }
      
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

73 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

OnMouseDown() function is not changing gameobject declared outside. 1 Answer

comparing variables of gameobjects in an array 2 Answers

same script on multiple objects access to different variables from another script 0 Answers

cant set object in prefab object, but can in the scene 1 Answer

Finding the Sum of Values of Multiple GameObjects in an Array + Variable Sized arrays 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges