Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

354
Visualizações
Listen for key input from editor script

I am using an editor script placed in editor folder, which listens to a key pressed. When the key is pressed, it is supposed to trigger a function from MonoBehavior script. The issue is that the function does not get triggered at all. I am even adding EventSystem in my inspector. What is the problem here? :

[CustomEditor (typeof (Switcher))]
public class SiwtcherEditor : Editor {
    void OnSceneGUI () {
        Switcher script = (Switcher) target;
        Event e = Event.current;
        switch (e.type) {
            case EventType.KeyDown:
                {
                    if (Event.current.keyCode == (KeyCode.A)) {
                        Debug.Log ("A pressed");

                        script.SwitchHere();
                        e.Use ();
                    }
                    break;
                }
        }
    }
}
public class Switcher : MonoBehaviour {
    public void SwitchHere () {
        Debug.Log ("GotINPUT"); 
    }
}

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If someone comes across this problem, the issue was that OnSceneGUI() was not getting called. So the problem is resolved by OnEnable() function as given below:

[CustomEditor (typeof (Switcher))]
public class SiwtcherEditor : Editor {
    void OnSceneGUI (SceneView sceneView) {
        SceneView.RepaintAll ();
        Switcher script = (Switcher) target;
        Event e = Event.current;
        switch (e.type) {
            case EventType.KeyDown:
                {
                    if (Event.current.keyCode == (KeyCode.A)) {

                        script.SwitchHere();
                        e.Use ();
                    }
                    break;
                }
        }
    }

 void OnEnable () {
        SceneView.duringSceneGui += OnSceneGUI;
    }

    void OnDisable () {
        SceneView.duringSceneGui -= OnSceneGUI;
    }
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda