- Home /
Why is text ui cant be static ?
Hi there ! I was asking to myself this question cause in my project, i got for now 2 different scripts in 2 different gameobjects. In one got boxcollider, and the second object behavior. But I need to call a function with text (to actually refresh and update the score) from the one containing object beahvior to the one containing boxcollider. Everything could work well as I set all I need as public and static, but when i do that for the text component, it disapears from the gameobject in the unity interface.
Do you know if there is a way to use text as public and static ?
Cause it says " an object reference is required for the non static field..." when I try to call my method from the other script. It's ok when I make it static but as I do this, text is not accessible anymore
It says that because you were trying to access an object's field without having an instance of the object first ($$anonymous$$eaning you were trying to use the class ins$$anonymous$$d). Sure you can make it static but that is not a real solution. You shouldn't make things static just because you want to access them from other scripts, that's a bad coding habit and not object oriented program$$anonymous$$g at all. Would you $$anonymous$$d showing your code so I can better understand the intent here and provide an alternative?
Your answer
Follow this Question
Related Questions
Static Facing an Object 2 Answers
Calling Update function in another function (JS) 1 Answer
Quest Script Help 2 Answers
Setting public GameObject to a different Prefab through code 0 Answers
error CS1525: Unexpected symbol `public' 2 Answers