Search Unity

Question Event.shift does not work with unity v2019.3.2f1

Discussion in 'Scripting' started by greatowq01, Nov 19, 2020.

  1. greatowq01

    greatowq01

    Joined:
    Dec 16, 2018
    Posts:
    37
    Scripting Example in Unity documentation about Event.shift doesn't work with unity v2019.3.2f1, but it works with v2018.3.8f1 and v2020. Is it a bug?

    Here is the code from Unity documentation(v2019.4):

    Event.shift

    MonoBehaviour
    {
    // Detects if the shift key was pressed
    void OnGUI()
    {
    Event e = Event.current;
    if (e.shift)
    {
    Debug.Log("Shift was pressed :O");
    }
    }
    }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Does it work with the latest Unity 2019.4 release?
     
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    If you need a work-around, you might try Input.GetKey instead. (Although that is probably only updated once per frame.)
     
  4. greatowq01

    greatowq01

    Joined:
    Dec 16, 2018
    Posts:
    37
    I havent tried that yet. The code above is the same as that from Unity documentation(v2019.3)
     
  5. greatowq01

    greatowq01

    Joined:
    Dec 16, 2018
    Posts:
    37
    In my project, I want to get input-keycodes with OnGUI method. So, Event.current is needed.
     
  6. greatowq01

    greatowq01

    Joined:
    Dec 16, 2018
    Posts:
    37
    It confuses me that Event.current can get all Keycodes with Unity 2018.3.8f1, but cant get leftshift or rightshift with v2019.3.2f1.
     
  7. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Is there a reason you can't use Event.current to detect events while using Input.GetKey to determine whether the shift key is down at the time those events occur?
     
  8. greatowq01

    greatowq01

    Joined:
    Dec 16, 2018
    Posts:
    37
    No,I dont use Input.getkey in OnGUI(). and the script is the same as the example above. There are no other codes like input.getkey in the script tested.
     
  9. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    The question you are answering is not the one I asked.
     
  10. greatowq01

    greatowq01

    Joined:
    Dec 16, 2018
    Posts:
    37
    Event.current should be able to detect events like the shift key is down at the time those events occur with all unity releases.
     
  11. greatowq01

    greatowq01

    Joined:
    Dec 16, 2018
    Posts:
    37
    It works with 2019.4 release. I just tested it. Look at the following images.
    upload_2020-11-21_18-9-10.png
    upload_2020-11-21_18-10-12.png
     
  12. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Ok great so can you just use 2019.4? Unity doesn't support non-LTS releases so it won't be fixed in 2019.3.
     
    Bunny83 likes this.
  13. greatowq01

    greatowq01

    Joined:
    Dec 16, 2018
    Posts:
    37
    Well, that can be a work-around. Thanks.