Search Unity

[SOLVED] using "using" reserved word as a function, inside another function (OnSceneGUI)

Discussion in 'Immediate Mode GUI (IMGUI)' started by jazzbach, Jan 23, 2020.

  1. jazzbach

    jazzbach

    Joined:
    May 11, 2016
    Posts:
    19
    Hello,

    I'm following a tutorial on editor scripting (https://learn.unity.com/tutorial/editor-scripting#5c7f8528edbc2a002053b5fb) and there's a snippet of code that I find difficult to understand:

    On line 9, the code uses the reserved keyword "using" but I don't understand the purpose of using it here or even why is it being used similar as a function declaration ?

    Any help will be deeply appreciated.

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. [CustomEditor(typeof(Launcher))]
    4. public class LauncherEditor : Editor
    5. {
    6.     void OnSceneGUI()
    7.     {
    8.         // HERE IS MY QUESTION: Why using "using" like this:
    9.         using (new EditorGUI.DisabledGroupScope(!Application.isPlaying))
    10.         {
    11.             if (GUILayout.Button("Fire"))
    12.             {
    13.                 // Do something
    14.             }
    15.         }
    16.     }
    17. }
     
  2. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    42
  3. jazzbach

    jazzbach

    Joined:
    May 11, 2016
    Posts:
    19
    Thank you so much for the explanation JoNax97 ! I now understand it. :)
     
    JoNax97 likes this.
unityunity