Skip to main content

Posts

Showing posts with the label GUI

Making Multiple Instances of Windows With Same Window Method

So when developing a small little web-player, I ran into the problem of trying to render multiple instances of the same window function. My plan was for my user interface component to iterate through all the thought components and for each thought, render its contents in a new window. The windows need to be draggable also. My first attempt of this implementation failed. Rect thoughtRect = new Rect(20, 20, 200, 100); void OnGUI(){ for (int i = 0; i < allthoughts.Length; i++){ thoughtRect = GUI.Window(0+i, thoughtRect, DoThoughtWindow, ""+allthoughts[i].GetContent()); } } void DoThoughtWindow(int windowID) { GUI.DragWindow (new Rect(0, 0, 10000, 10000)); } For those who don't see the problem with this, I'll explain. All three windows are using the same Rect  thoughtRect  so all the windows are drawn on top of eachother. You might think this won't pose a problem due to the windows be...

GUI Basics

So every game has some type GUI (graphic user interface). The best way (as I see it) is scripting the GUI. Very simple, so something easy to start with: function OnGUI(){ GUI.Box(Rect(10, 10, 90, 90), "Hello!"); } Rect - Shape the box will be, rectangle. (10, 10, 80, 90) 10 - How far away it begins from the left of the screen. 10 - How far away it begins from the top of the screen. 80 - Total width of rectangle. 90 - Total height of rectangle. "Hello!" - Text that shows up in the box.