- Home /
Scripted UI.text not shows on duplicated object
Hey, I liked in Unity 4 to dynamicaly change just one GUItext via script. In Unity 5 is pretty easy too, but I've faced minor problem. More experienced developer could know, why is it behaving like that.
Lets say we have Cube (rigid+box collid) and we change text on mouseover(), or when clicked (picking up object in hand) so ve have set 2 UI.texts in Canvas, which are assigned into script slots (this is small part of code):
public var textObject : GameObject;
public var textHoverer : GameObject;
private var isHolding = false;
private var isOn = false;
function OnMouseOver(){isOn = true;}
function OnMouseExit(){isOn = false;}
//update()
if(isOn==true) textHoverer.GetComponent(UI.Text).text = "This is a box.";
if(isOn==false) textHoverer.GetComponent(UI.Text).text = "";
if(isHolding == true){
textObject.GetComponent(UI.Text).text = "You can rotate me by pressing Y or X";
textHoverer.GetComponent(UI.Text).text = "";}
Easy. But when I duplicate Cube (even prefabbed) to Cube-1 and assign same text objects to script slots, UI.texts are empty. I had to assign another UItexts objects (text duplicates) to script slots to make it work again as 1st Cube. How so? Calling UI.texts via Find or Tag not helps. It just wants another UI.text objects to show text, when same script is on Cube-1, then it works as expected again. I don't want to have like 100 UI.texts in canvas in final game :) But in worst case I can go with it for sure :)
Is it something related with mouseover(), should I use raycast?
or maybe because if-statement (false) in update() constantly updating text to = ""; so it actually can't change? That maybe seem logic...
Did you ever find a solution to this? I'm having a similar issue.
solution is to leave unity and start to develop in unreal ;)
Your answer
Follow this Question
Related Questions
Text wont change to correct value 1 Answer
Quest Script Help 2 Answers
What's your equivalent of old GUIStyle ? 0 Answers