- Home /
Converting OnGUI function to UI
I found some scripts about making dialogues in game, but these scripts use old GUI, and now i need to convert it to UI. Could somebody please help me with this?
Other scripts related: https://pastebin.com/QZamw5Jc https://pastebin.com/bx1Xi426
I appreciate any help, guys.
Answer by FlaSh-G · Aug 06, 2017 at 09:46 AM
You can't convert an IMGUI (OnGUI) script for the new UI. The new UI consists of GameObjects added to a canvas GameObject, with positions and dimensions set in the respective transform components. Events like having clicked on a button are set using the UnityEvents that are displayed in a component's inspector. In other words: Half of what this script does is not done by scripting in the new UI, and the other half depends on how you designed the first half.
I'd recommend either
understanding the script you found and re-implementing the idea behind it or
trashing the script and start from scratch.
The good news is: The new UI is surprisingly intuitive and fun to use once you get the hang of it. Instead of one complex OnGUI function, you can implement a lot of things with a few one-liner scripts that you attach to the right UI objects. Here's the tutorials section for the new UI to get you started: https://unity3d.com/de/learn/tutorials/topics/user-interface-ui
Your answer
Follow this Question
Related Questions
Problem with GUI element following enemy 0 Answers
Bad result of changing RectTransform values (Anchor Preset) programmatically 0 Answers
Can I do a "rotatory" UI like this? 1 Answer
What is the right choice for UI Performance? 0 Answers
Is there still have the old UI color theme in Unity 3 Pro? 2 Answers