how to call event function for keys mono-behaviour C#

  1. I’m trying to make an event that won’t be called every frame but ONLY when event happens is it possible? if it’s impossible

  2. how to call input so I verify in Update if correct thing was pressed (Forward is dinamic string (it changes dependent on the controlls user set it up)) if it’s impossible

  3. is it really the least efficient way calling 60 or more controlls per frame just to walk forward?

  4. and if I have OnGUI () {} does it take more process?

    public string Forward = “W”;
    void OnKeyDown () {
    Debug.Log(“ehgauebw”);
    }

    void Update () {
    if (Input.GetKey().ToString == Forward) {
    Debug.Log(“ehgauebw”);
    }
    }

    void OnGUI (){
    if (Event.current.keyCode.ToString() == Forward){
    Debug.Log(“sdeiflgh”);
    }
    }

Check the Scripting Reference. GetKey takes a string or KeyCode argument, Event.current.keyCode is a KeyCode, so you should store your control as a KeyCode.