Hi all, I’m using Unity 5.1.1f1. I have a problem where I’m trying to read the value from a new UI text field like so:
public class UIController : MonoBehaviour
{
public Text email;
public void OnClickGo ()
{
Debug.Log ("email is: " + email.text);
}
}
The problem I have is that when I print the value out, it truncates the value of the text box to the visible part and truncates either the left or right side of the text value.
I can’t see any way to get the full text value in C#. The text is still in the UI if I manually scroll left or right.
Any ideas?
Of course as soon as I posted this, I found the line in the InputField docs that says not to get the text value this way. For anyone else that trips on this, use InputField to read the text value, not Text component.
public class UIController : MonoBehaviour
{
public InputField email;
public void OnClickGo ()
{
Debug.Log ("email is: " + email.text);
- Hello, I’m new at unity and the forum as well. Because of this i’m not sure where to post this
- If someone could help me would be super nice.
- I’m having problems with this “.text” stuff.
- Obs: I tried to use the GUIText, that seems to be an older version of the UI tools, and it worked on other scripts…
- Thank you very much!
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Try to use the UnityEngine.UI but it's not accesing anything.
public class Test : MonoBehaviour {
public Text txt; // Created the variable txt of the TextSize;
void Start () {
txt.text = "test in main" // Here I'm trying to test the ".text" in the Main function;
}
// Update is called once per frame
void Update () {
txt.text = "test in Update"; // Here I'm trying to test the ".text" in the Update function;
}
}