Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Problem with an error.

Discussion in 'Editor & General Support' started by LHarris134, Dec 30, 2015.

  1. LHarris134

    LHarris134

    Joined:
    Feb 14, 2015
    Posts:
    6
    I'm having a scoping problem in my code. I don't understand why though.
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4. using System.Collections;
    5.  
    6. [CustomEditor(typeof(Grid))]
    7. public class GridEditor : Editor
    8. {
    9.     Grid grid;
    10.  
    11.     void OnEnable()
    12.     {
    13.         grid = (Grid)target;
    14.     }
    15.  
    16.     public override void OnInspectorGUI()
    17.     {
    18.         //base.OnInspectorGUI ();
    19.  
    20.         GUILayout.BeginHorizontal ();
    21.         GUILayout.Label ("Grid Width");
    22.         grid.width = EditorGUILayout.Slider (grid, width, 1f, 100f, null);
    23.         GUILayout.EndHorizontal ();
    24.     }
    25.  
    26.  
    27. }
    The error is on line 22. The compiler is having a problem with my width variable for the slider. The slider takes 5 arguments 4 floats and an instruction. Now In another script i have defined width as a float. I thought that i brought in my other script into this one by doing Grid grid; So the scope should work. The exact error is width doesn't exist in this context. Any suggestions on why it's not reading my width?
     
  2. LHarris134

    LHarris134

    Joined:
    Feb 14, 2015
    Posts:
    6
    Figured it out. i had a typo. should have been gird.width = EditorGUILayout.Slider(gird.width, 1f,100f,null);