0
Answered

Convert text (Localized) to string

markusrgb 2 months ago in Game Creator updated by Marti (Lead Developer) 2 months ago 3


Hello,

I have a text (Localized) on my game objects (enemies, trees etc.) which contains a short description of the target. But I can't find a way to display it as a string in my user interface.

I use a target system that shows me enemies or objects in the vicinity of the player with the help of tags. This works quite well except for the fact that I can't find a way to display the text that is on the target in the UI.

I have been trying it for 2 days now but I can't think of a suitable solution.

It is possible to transfer a string from a variable to a test, but unfortunately there is no function that works the other way around.

So once my target system has found a target, I want it to show me the text on it in the UI while it is tracted.

I have also tried to work with messages, but unfortunately this does not work with UI either.

Am I missing something here?

Unity version:
2019.4.0f1
Game Creator version:
1.1.9
BAD, I'M UNSATISFIED

Hi, Marti,

Perhaps I should have asked my question more precisely.

I know myself that I can display a text element with a canvas.

Unfortunately this does not answer my question.

I am looking for a way to store a text (translated) in a string variable.

;)

Satisfaction mark by markusrgb 2 months ago
Answered

The Text (Localized) component is a UI element. You need to use this component together with a Canvas game object. For more information on how to use the UI in Unity, see the Unity Learn section.

The Text (Localized) component is basically Unity's Text component, but the text's language is automatically updated when changing to another language.

I would have wanted to exchange a text on my UI with a text(localized) that is on my opponent. Unfortunately this does not seem to work. It would have made sense to use a function that stores a text in a string variable (but this function does not exist). Then I would have wanted to display this string in another text field (This function exists)

I've come up with a different solution. I have now created a suitable text(localized) for each target object. Then I query in a separate condition which target object it is and then show or hide the corresponding text.

Understood. Sorry for the confusion. There isn't one at the moment that does this, although I'm opening a ticket to see if it fits for an update.

The main problem at the moment is that the localization parsing happens inside a class that is exclusive to some components (like Text (Localized)). Despite this, you can still recover the text from a Text (Localized) component by accessing the text field:

//public TextLocalized myTextReference;
string translation = this.myTextReference.text;