Hi! I’ve got a problem with editing new UI Text from script. I attached this (part of) script to my UI Text gameObject:
score = GetComponent<Text>();
score.text += objects.Player_Score;
and I received this compilation fail:
Assets/Scripts/Menu/gameOverScoreDisplay.cs(6,9): error CS0246: The type or namespace name `Text’ could not be found. Are you missing a using directive or an assembly reference?
What should I do to use ‘Text’ type in my scripts? I saw the same part of script in the official
Unity video (1)… Yes, I’ve got the newest Unity update (4.6).
You need to put reference to namespace, where new UI classes contains:
Or you also can refer to this type as
score = GetComponent<UnityEngine.UI.Text>();
Maybe you forget adding using UI
About editing text in UI from script you can see here :
If you’re having trouble using JS, try the following:
// at the top of your code where you declare variables
var score: UnityEngine.UI.Text;
// no need to do anything inside Start() unless you would like to set an initial value