How do I make it so I can use strings in my unity UI TMPro? I also need to know when I should use the different strings as two strings are for when crafting an object fails, like is there to many objects or to few, ande one is for then I succeed to craft an object.
The three texts are "try to remove an object to craft a "+outcome // "try to add an object to craft a "+outcome // "You succeeded in crafting a "+outcome
The recepies and materials are deffined with items which has Data-packages connected to them through an Item script. Every item has their own IDs.

Tuhin PaulRank #7 · 71.9K reputationPosted Feb 25, 2023, 4:50 AM EST
Hi Lucas,
To use strings in Unity UI TMPro, you can follow these steps:
1. Add a TextMeshProUGUI component to your UI element, such as a Text or InputField object.
2. In the Inspector panel, expand the TextMeshProUGUI component and find the "Text (TextMeshProUGUI)" field.
3. In the "Text (TextMeshProUGUI)" field, you can type in your desired string directly, or you can reference a string variable.
4. To reference a string variable, you can create a public string variable in your script and assign it a value in the Inspector panel. Then, you can reference this variable in the "Text (TextMeshProUGUI)" field by using the format "{variableName}".
Here's an example of how you could use string interpolation in C# to update the craftingText variable with the crafting outcome text:
// Assuming item is an Item object with a Data-package containing the crafting outcome text string outcomeText = item.Data.OutcomeText; // Get the crafting outcome text from the item's Data-package string craftingText = ""; // Initialize the craftingText variable if (/* check if the player has too many objects for the crafting recipe */) { craftingText = $"try to remove an object to craft a {outcomeText}"; // Use string interpolation to insert the outcome text } else if (/* check if the player has too few objects for the crafting recipe */) { craftingText = $"try to add an object to craft a {outcomeText}"; // Use string interpolation to insert the outcome text } else { craftingText = $"You succeeded in crafting a {outcomeText}"; // Use string interpolation to insert the outcome text } // Assign the craftingText variable to the "Text (TextMeshProUGUI)" field of your UI element TextMeshProUGUI craftingTextUI = GetComponent(); // Get the TextMeshProUGUI component of your UI element craftingTextUI.text = craftingText; // Assign the craftingText variable to the "Text (TextMeshProUGUI)" fieldIn this example, we're assuming that the Item object has a Data-package containing the crafting outcome text, which we're storing in the outcomeText variable. We then use an if-else statement to check whether the player has too many or too few objects for the crafting recipe, or whether they've successfully crafted the object. Depending on the outcome, we use string interpolation to insert the outcome text into the craftingText string. Hope this helps