Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Why is input mouse clicking not working on WebGL build?

Discussion in 'Input System' started by coder_58, Sep 7, 2021.

  1. coder_58

    coder_58

    Joined:
    Mar 29, 2020
    Posts:
    31
    Hi,

    I made an FPS game in unity3d and exported it to webgl (unity play). When I played that, however, and clicked on a gameobject, nothing happened. The gameobject was supposed to rotate on click. Even when I tried clicking on other similar gameobjects, the same issue persisted. I'm not sure why this is happening...can someone please help? Thanks.

    I'm using Input.GetMouseButtonDown(0) for those particular mouse clicks. For the FPS controller, I'm using unity's standard assets Rigidbody FPS controller.

    Here's my code containing basically all of my mouse-click related actions:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEditor;
    4. using UnityEngine.UI;
    5. public class OpenPaint : MonoBehaviour
    6. {
    7.  
    8.     public bool isOpen = false;
    9.     public bool drawOpen = false;
    10.     public bool isLift = false;
    11.     public bool canUncScream = false;
    12.     public GameObject battery1;
    13.     public GameObject battery2;
    14.     public GameObject battery3;
    15.     public GameObject safe;
    16.     public GameObject scream;
    17.     public static bool enableBatteries = false;
    18.     public GameObject clue1;
    19.     public GameObject inputField;
    20.     public GameObject pwQs;
    21.     void Update()
    22.     {
    23.         if (Input.GetMouseButtonDown(0)) //FOR MOUSE CLICKS
    24.         {
    25.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    26.             RaycastHit hit;
    27.             if (Physics.Raycast(ray, out hit))
    28.             {
    29.                 Debug.Log("Name = " + hit.collider.name);
    30.                 Debug.Log("Tag = " + hit.collider.tag);
    31.                 Debug.Log("Hit Point = " + hit.point);
    32.                 Debug.Log("Object position = " + hit.collider.gameObject.transform.position);
    33.                 Debug.Log("--------------");
    34.                
    35.                 if (hit.collider.tag == "book1")
    36.                 {
    37.                     StartCoroutine(showClue1());
    38.                     Debug.Log("ssssscxxsx");
    39.                     enableBatteries = true;
    40.                     addStuff();
    41.                 } else if (hit.collider.tag == "painting"){
    42.                      isOpen = !isOpen;
    43.                      hit.collider.gameObject.GetComponent<PaintingOpen>().Uncover(isOpen);
    44.                  } else if (hit.collider.tag == "pillow"){
    45.                      isLift = !isLift;
    46.                      hit.collider.gameObject.GetComponent<LiftPillow>().Lift(isLift);
    47.                  } else if (hit.collider.tag == "tvdrawer"){
    48.                      drawOpen = !drawOpen;
    49.                      hit.collider.gameObject.GetComponent<OpenDrawer>().OpenDraw(drawOpen);
    50.                  } else if (hit.collider.tag == "book"){
    51.                      if (PlayerCollisions.showedGJ){
    52.                          canUncScream = true;
    53.                         StartCoroutine(showPaintClue());
    54.                         safe.SetActive(true);
    55.                      }
    56.                  } else if (hit.collider.tag == "safe"){
    57.                      inputField.SetActive(true);
    58.                      pwQs.SetActive(true);
    59.                  }
    60.             }
    61.         }
    62.      
    63.  
    64.     }
    65.  
    66.     public IEnumerator showClue1() //NOT SHOWING WHEN BOOK1 IS CLICKED
    67.     {
    68.         clue1.gameObject.SetActive(true);
    69.         yield return new WaitForSeconds(10);
    70.         clue1.gameObject.SetActive(false);
    71.         enableBatteries = true;
    72.     }
    73.  
    74.     public IEnumerator showPaintClue(){
    75.         scream.SetActive(true);
    76.         yield return new WaitForSeconds(10);
    77.         scream.SetActive(false);
    78.     }
    79.  
    80.     void addStuff()
    81.     {
    82.         if (enableBatteries)
    83.         {
    84.          
    85.             if (battery1 != null && battery2 != null && battery3 != null)
    86.                 battery1.SetActive(true);
    87.                 battery2.SetActive(true);
    88.                 battery3.SetActive(true);
    89.  
    90.         }
    91.  
    92.     }
    93.  
    94.  
    95. }
    I've put all of the public gameobjects in their respective slots in the inspector, everywhere, and I've checked all of the methods using parameters and ensured they're called correctly. All seems fine regarding this. Plus, it all works within the Unity application itself.

    How do I fix my mouse click when it's not working on WebGL build? Thanks.