- Home /
Using GUIStyles/GUISkins with GUIText objects?
I initially learned how to make GUI's using OnGUI, but since it's inefficient for mobile devices I'm switching over to using GUIText objects. The one thing that I can't figure out is how do I assign a GUIStyle or a GUISkin to my GUI.Text? It has no variable for this like a GUI.Label does, and a GUISkin has no setting for GUI.Texts... it just has text fields and text areas, neither of which apply to my GUITexts.
Are GUIStyles and GUISkins only used with OnGUI? If so, how do I create some template GUI settings to apply to multiple GUITexts so I don't have to manually set this stuff every time?
Answer by Eric5h5 · May 19, 2014 at 10:17 PM
GUIText objects are a separate system from OnGUI code and the two do not interact in any way. OnGUI isn't that inefficient, so I'd recommend not switching anything. You'll gain little or nothing by using GUIText objects.
Having looked around quite a bit on the topic, you seem to be in the $$anonymous$$ority with that opinion. Everything I've read has basically said that OnGUI is checking up to twice every frame plus once every event call, and most everybody (including Unity themselves) say DON'T use OnGUI for mobile games.
Also, this isn't an answer. Can you answer my actual question about how to create some template style (like a GUIStyle) but for a GUIText object?
That advice was from years ago when mobile devices were much slower and more limited. A modern mobile device won't have any issues with OnGUI unless you push it really hard. It's never a good idea to make changes unless you actually know for sure that what you're doing is a problem that needs to be solved. Don't make assumptions: profile first.
And yes, it's an answer. Your question was using GUIStyles with GUIText objects, and the answer is that it's not possible. I'm sorry if you don't want to hear that, but nevertheless it's true.
Dude, not everybody has a "modern" mobile device. I'm still trying to support older devices so this is a completely valid concern. I don't need to profile, because I don't even have the devices that I'm trying to code for.
And my question was specifically asking what you do to save settings across multiple GUITexts in the event that you can't use GUIStyles. You didn't answer that... just reiterated that I can't use GUIStyles. I get it. But is there an alternative for GUITexts?
Yes, basically everybody who runs Unity content has a modern mobile device. How big of a marketshare do you think the iPhone 1 has these days? Unity doesn't even have the option to do OpenGLES 1.0 or publish to anything less than iOS 4.0 anymore. $$anonymous$$obile hardware changes fast.
There are no GUIStyles or any way to do templates for GUIText objects, obviously aside from just duplicating an existing object and changing the text. They are very old and fairly primitive (from Unity 1 days). Again, sorry, but sometimes you just have to accept that the answer is "no".