Search Unity

Spacebar executes function but it is not programmed to

Discussion in 'Scripting' started by Steve-Tou, Mar 16, 2019.

  1. Steve-Tou

    Steve-Tou

    Joined:
    Aug 4, 2018
    Posts:
    10
    I have buttons that are assigned (via OnClick+ in the inspector) simple functions from the same class that moves gameobjects(of different categories I have tagged them). Once one button is clicked all buttons disappear. I am also using the Unity FPC to move around the scenes. I have added some modifications to the FPC script to freeze the mouse pan when holding down E. But I have not made or modified any code using the spacebar (jump). Problem--When I press the spacebar (jump) after I have already clicked a button, the script that is assigned to my button(s) executes (sometimes), which moves gameobjects I don't want moved. I'm using version 2017.1.0p4. This happens in both editor and builds.
    I've tried commenting out the jump in the FPC script- it works fine, but the spacebar still executes my function. (My game doesn't involve jumping, so this would be ok). Anyone have an idea why this might be occurring? Thanks.
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    Spacebar is also assign to submit in the event system. The issue is that the button is still the active object in the ui.
     
    Steve-Tou likes this.
  3. Steve-Tou

    Steve-Tou

    Joined:
    Aug 4, 2018
    Posts:
    10
    Hmmm... When I click the button(s), it sets the parent canvas to enabled=false. I guess disabling the canvas doesn't necessarily cause a focus loss from the child buttons?? Anyways, I deleted the 'enter', 'return', and 'space' keys from the Submit functions in the Input Manager, in effect disabling these keys. (If I decide I need them later, I will have to program focus changes, but for now this works.) Thanks for the answer- it got me where I needed to go.