Unity Windows in Unity

This topic is 963 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm trying to find a way of opening some windows with some info by pressing a button.

I have a loop that looks like this:

  if (System.SystemSize >= 5)
{
scrollPosition = GUI.BeginScrollView(new Rect(5, 100 + GUIPlanetPosition, 225, 400), scrollPosition, new Rect(0, 0, 50, 750));
for (int i = 0; i < System.SystemSize; i++)
{
GUI.Button(new Rect(25, 100 + GUIPlanetPosition, 175, 40), Planet[i].PlanetName); // Press to show info in new window, each button shows different info
GUIPlanetPosition = GUIPlanetPosition + 50;
}
GUI.EndScrollView();
}

My question is if anyone knows of a way to do this in Unity. As far as I can tell, even if I manage to draw a new window, it would draw for 'i' times, so what could I use in this case?

Share on other sites

Without going to actually look, I believe the commonly used method is to have the window already created and toggle its 'active' state when you want it to appear.

Share on other sites

Since (4.6ish?) Unity has a new UI system, based less on code and more on the scene editor. There are a lot of different UI elements that can be put on a canvas that renders over the screen, and these could be set to enable/disable with a script.

UI component tutorials:

https://unity3d.com/learn/tutorials/topics/user-interface-ui

Edited by SpikeViper

Share on other sites

My question is if anyone knows of a way to do this in Unity. As far as I can tell, even if I manage to draw a new window, it would draw for 'i' times, so what could I use in this case?

Yes, don't use that system.

The old UI system was somewhat confusing to use and difficult to use well. It was designed with a different mindset from what most people thought about in a UI. It assumed the people using the UI system had a background in using lightweight self-processed UI elements rather than the event-driven model so many people prefer. It had many potentially-confusing quirks such as updating at least every video frame rather than updating every simulator update (those are generally different rates), and updating multiple times based on events being triggered (such as many mouse movements detected during a single graphics frame).  Trying to explain to someone why their UI code was called a seemingly random number of times over a different duration was often done poorly. Couple that with people not writing code that worked well with the UI system's design, treating it like an update and event-driven system and less like a self-processed probe, and the end result was that very few people used their old UI system well and they decided to rewrite it.

The rewritten UI system (linked in the post above) is in my view less elegant and more bloated internally, but externally it is easier for people to use in their more familiar model.  It takes more internal processing work, but most developers don't seem to mind in favor of more friendly development.

Share on other sites

Their new system makes me miss XAML.  Or at least XAML grids.

Share on other sites

I guess I should start creating buttons individually instead of using that loop. Thanks for all the help.

1. 1
2. 2
3. 3
Rutin
20
4. 4
khawk
14
5. 5

• 9
• 11
• 11
• 23
• 12
• Forum Statistics

• Total Topics
633655
• Total Posts
3013187
×