- Home /
The question is answered, right answer was accepted
How to make official localization mix strings with scripted variables?
I'm a newbie unity user who has never written a code before starting to learn unity couple weeks ago. Now i'm trying to learn how to implement a localization into game using official unity localization https://docs.unity3d.com/Packages/com.unity.localization@0.9/manual/index.html i have no problem using it for simple strings. But there is a string in my game which before implementing localization was defined like this along with the other stuff inside GameManager.cs:
public TextMeshProUGUI scoreText;
public int score;
public void UpdateScore (int scoreToAdd)
{
scoreText.text = "Score: " + score;
score += scoreToAdd;
}
How to make localization for this string without splitting it into 2 different objects (one for "Score:" string and another for score value). I've tried making a smart strings in localization table like these
Score: {score}
Очки: {score}
etc. or like these
Score: {GameManager.score}
along with removing scoreText.text = "Score: " + score; from my script but this way it's just displaying the first part of the string from localization table
Score:
Очки:
etc. How to make it work considering that my scripting skills are very low at the moment?
Answer by viv5552 · Jan 11, 2021 at 08:32 AM
I should've added to text gameobject a script whose only purpose is defining score variable and then drag that script into Format Arguments field of Localize string event component in Inspector
Follow this Question
Related Questions
How to make localization for Dropdown - TextMeshPro? 0 Answers
How to switch language in-game using official unity localization 0.9? 1 Answer
Change gameObject within a Transfom 1 Answer
Add Force At Player 0 Answers
When should I use prefabs? 2 Answers