- Home /
UI: Loading the text in a Text type with a String?
Using the new Unity4.6 UI System;
I've got a Text type loaded onto a canvas that I need to update with a string. In attempting to update a text component as follows;
myObject.getComponent<Text>().text = passedString;
I'm sent back an error stating that a String type cannot be implicitly converted to a Text type. Casting passedString manually also doesn't make any difference.
I've found I can actually hack around it with;
myObject.getComponent<Text>().text = "" + passedString;
But this at least, looks like terrible practice.
Could anyone let me know what the correct way of converting a String to a text type is?
Answer by shriya · Dec 24, 2014 at 05:12 AM
Hi, I don't think you are doing anything wrong. Still try this:
using UnityEngine.UI;
public class yourClass : MonoBehaviour
{
public Text largeAlphabetHighlighter; // Pass this value from inspector..
void Start()
{
largeAlphabetHighlighter.text = passedString;
}
}
Your answer
Follow this Question
Related Questions
Graphic problem with UI Text 2 Answers
How to get the width of UI Text with Horizontal Overflow? 4 Answers
What's your equivalent of old GUIStyle ? 0 Answers
Display text above prefabs in Unity 4.6 0 Answers