Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WebGL Not receving keyboard input in some browsers

Discussion in 'Unity 5 Pre-order Beta' started by noamgat, Jan 30, 2015.

  1. noamgat

    noamgat

    Joined:
    Nov 22, 2009
    Posts:
    125
    I uploaded a WebGL build of our global game jam 2015 game to itch.io here :

    http://noamgat.itch.io/one-button-to-rule-them-all

    In Firefox on windows, the game works well. However, in chrome on windows and safari on OSX, the game does not respond to keyboard input (space should perform the action, but only the mouse does in the browser).

    Is this a known bug? Does anyone know how to work around it?

    The input code is extremely straighforward :
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class InputManager : MonoBehaviour {
    5.  
    6.     public static bool GetButtonDown { get; private set; }
    7.     public static bool GetButtonUp { get; private set; }
    8.     public static bool GetButtonHeld { get; private set; }
    9.  
    10.     // Update is called once per frame
    11.     void Update () {
    12.        
    13.         GetButtonDown = false;
    14.         GetButtonUp = false;
    15.         GetButtonHeld = false;
    16.  
    17.  
    18.         if (Input.GetButtonDown("Fire1") || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began))
    19.         {
    20.             GetButtonDown = true;
    21.         }
    22.  
    23.         if (Input.GetButtonUp("Fire1") || (Input.touchCount > 0 && ((Input.GetTouch(0).phase == TouchPhase.Ended) || (Input.GetTouch(0).phase == TouchPhase.Canceled))))
    24.         {
    25.             GetButtonUp = true;
    26.         }
    27.  
    28.         if (Input.GetButton("Fire1") || (Input.touchCount > 0 && ((Input.GetTouch(0).phase == TouchPhase.Stationary) || (Input.GetTouch(0).phase == TouchPhase.Moved))))
    29.         {
    30.             GetButtonHeld = true;
    31.         }
    32.     }
    33. }
    34.  
     
    Last edited: Jan 30, 2015
  2. sokki

    sokki

    Joined:
    Jan 31, 2015
    Posts:
    166
    The game takes too much time to load.

    On the other hand, its unique how you combine 3 different games/modes into one highscore game. To complex for me thou.

    Do you work on other WebGL games? I might have an offer for you :)
     
  3. SrNull

    SrNull

    Joined:
    Jun 9, 2011
    Posts:
    25
    Im having the same issue when I submit Unity WebGL to newgrounds , I dont know how to get rid of it.
    Only thing i can be sure is that is a focus problem in the HTML, you need to clic on the webgl element to start receiving the keyboard input,