Search Unity

[SOLVED]Gui js to c# convertion / Gui Overlay Order question

Discussion in 'Immediate Mode GUI (IMGUI)' started by akaadan, Sep 18, 2009.

  1. akaadan

    akaadan

    Joined:
    Sep 18, 2009
    Posts:
    2
    Hi,

    I may have a good technical background but I'm new to scripting in general, so please be patient with me.

    1. So For my first question, its quite simple, yet I can't find an answer to it. How do I convert the "style" gui variables and gui methods from javascript to c#? for example, I want to change these lines of code to c#:

    Code (csharp):
    1.  
    2. var shellTL : GUIStyle;
    3. GUI.Box (Rect (0,0,300,350), "This is a box", shellTL);
    4.  
    2. My second question involves changing the order of which GUI elements are placed on the screen. It seems to me that GUI elements are arranged based on the order of the lines of code, for example, if I have two GUI boxes on top of each other, the one on the top would be the one that is following the first one in the script. So the one coming second in the script always overlays the first one. My question is, is there a way to change that system of order so that I can specify which one would go on top and which one would go on the bottom? (similar to z-index in css)

    Any help would be appretiated :) Thanks in advance
     
  2. Timmer

    Timmer

    Joined:
    Jul 28, 2008
    Posts:
    330
    First: no worries! :)

    I definitely recommend doing some pure C# tutorials online or even a book if you're going that direction, though.

    1. Since it needs to be part of a class you'll have something like this:
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class SomeGUIClass : MonoBehaviour
    4. {
    5.    public GUIStyle shellStyle;
    6.  
    7.    void OnGUI()
    8.    {
    9.       GUI.Box(new Rect(0, 0, 300, 350), "This is a box", shellStyle);
    10.    }
    11. }
    Note that in C# to make a new object you need the 'new' keyword hence the "new Rect(...)" as the first argument.

    2. Look at the GUI.depth variable (higher numbers = to back).
     
  3. akaadan

    akaadan

    Joined:
    Sep 18, 2009
    Posts:
    2
    Thanks alot man! You rock! .. yea I'm learning C# as I go, and actually, I had the same exact code you did, except I forgot the "new", so it was giving me errors =P

    Both problems are resolved, again thanks a bunch for your help!!! =D