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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

GetKeyUp not working sometimes.

Discussion in 'Scripting' started by Shayke, May 24, 2018.

  1. Shayke

    Shayke

    Joined:
    Dec 8, 2017
    Posts:
    352
    Hey, I tryed to make some accelerator that while i click,then values are getting bigger and when i release the mouse button/touch/ pressing "space" something will happend.
    i am using those functions:
    Code (CSharp):
    1.        if (Input.touchCount > 0 || (Input.GetMouseButton(0)) || Input.GetKey("space"))
    2.             {
    3. //Do something
    4. }
    Code (CSharp):
    1.     if (Input.GetMouseButtonUp(0) || Input.GetKeyUp("space"))
    2.             {
    3. // Do something
    4. }
    It works totally fine but sometimes the release is not working.
    Any ideas?
     
  2. Shayke

    Shayke

    Joined:
    Dec 8, 2017
    Posts:
    352
    Edit: I think its because my function was at Fixed update.
     
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You're correct. Fixed Update can run >= 0 times per frame, so getting an Up or Down key (or button) during that method is not reliable. :)
     
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Never take input at FixedUpdate unless its checking if its down or not (getkey without up/down)