Search Unity

Better Know an Editor Script

Discussion in 'Scripting' started by orionburcham, Jun 27, 2011.

  1. orionburcham

    orionburcham

    Joined:
    Jan 31, 2010
    Posts:
    488
    I'm new to working with editor scripts, so I'm running some small tests to see what's possible. Right now I'm having trouble getting Inputs to work:

    I want this script to print its string when I press A from inside the editor:

    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. [ExecuteInEditMode]
    7.  
    8. public class PrintAInEditor : MonoBehaviour
    9. {
    10.     void Update ()
    11.     {
    12.         if(Input.GetKeyDown(KeyCode.A))
    13.         {
    14.             print("You have pressed A.");
    15.         }
    16.     }
    17. }
    18.  
    19.  
    20.  
    I have it on my mainCamera in a blank scene, but when I hit A, all I get is the 'apple alert' beep as though I've hit an invalid key. My first thought was that key inputs are locked from user control in editor scripts, but then again I've heard of people writing scripts with their own hotkeys.

    what am I doing wrong, or how is this done properly?

    Many Thanks!
     
    Last edited: Jun 27, 2011
  2. Tutanhomon

    Tutanhomon

    Joined:
    Sep 15, 2009
    Posts:
    101
    well I assume you have to make a custom editor for your script and check the input in OnSceneGUI function
     
  3. celadon

    celadon

    Joined:
    Oct 24, 2010
    Posts:
    16
  4. Dreamblur

    Dreamblur

    Joined:
    Jun 18, 2011
    Posts:
    183
    An Editor script is a script that inherits from the Editor class, not the MonoBehaviour class.
     
  5. Tutanhomon

    Tutanhomon

    Joined:
    Sep 15, 2009
    Posts:
    101
    also u can catch events - Event.current, and check ur input through it, scripting reference says abt it