I have a scene Scene001.
and a few UI objects which is Canvas and its child object Text. I have another scripted EmptyObject.
.Canvas (Tag: "canvas01")
...Text (Tag: "textTag")
.EmtpyObject (Script: "UniversalScript.cs")
I want to change the text in Text UI programmatically using the UniversalScript.cs script in EmptyObject.
However when I run it in Android devices, it keep telling me
NullReferenceException: Object reference not set to an instance of an object
I've tried the following methods and they are not working.
//01: GameObject gmobjCanv = GameObject.FindGameObjectWithTag("canvas01"); Canvas canvas = gmobjCanv.GetComponent<Canvas>(); Text textt = canvas.GetComponentInChildren<Text>(); // <- Error Here textt.text = "someText";
//02: GameObject gmobjTxt = GameObject.FindGameObjectWithTag("textTag"); Text textt = gmobjTxt.GetComponent<Text>();// <- Error Here textt.text = "replace with someText";
How should I do to solve this? Thanks.
Update 001: I've pointed in my code where the error occurs.
The error is telling me that the component [Text] in my "textTag" object is not found. But this is obviously easy to find right? just change text what? Again, I just want to change my text programmatically but it can't be done in my Android device. I don't found how is my question being duplicated? They are not solving my issue but explain generally how to avoid the issue.
BTW, somehow yes, it works in PLAY MODE, I din't build for other platforms, only for Android but it not works. I suspect my code might not really correct so I need a correct way to find and change my text.