Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Why is input mouse clicking not working on WebGL build?

adibak

New Coder
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 lang="csharp" title="Clicking-related actions" highlight="66, 23"]using UnityEngine;
using System.Collections;
using UnityEditor;
using UnityEngine.UI;
public class OpenPaint : MonoBehaviour
{

public bool isOpen = false;
public bool drawOpen = false;
public bool isLift = false;
public bool canUncScream = false;
public GameObject battery1;
public GameObject battery2;
public GameObject battery3;
public GameObject safe;
public GameObject scream;
public static bool enableBatteries = false;
public GameObject clue1;
public GameObject inputField;
public GameObject pwQs;
void Update()
{
if (Input.GetMouseButtonDown(0)) //FOR MOUSE CLICKS
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Debug.Log("Name = " + hit.collider.name);
Debug.Log("Tag = " + hit.collider.tag);
Debug.Log("Hit Point = " + hit.point);
Debug.Log("Object position = " + hit.collider.gameObject.transform.position);
Debug.Log("--------------");

if (hit.collider.tag == "book1")
{
StartCoroutine(showClue1());
Debug.Log("ssssscxxsx");
enableBatteries = true;
addStuff();
} else if (hit.collider.tag == "painting"){
isOpen = !isOpen;
hit.collider.gameObject.GetComponent<PaintingOpen>().Uncover(isOpen);
} else if (hit.collider.tag == "pillow"){
isLift = !isLift;
hit.collider.gameObject.GetComponent<LiftPillow>().Lift(isLift);
} else if (hit.collider.tag == "tvdrawer"){
drawOpen = !drawOpen;
hit.collider.gameObject.GetComponent<OpenDrawer>().OpenDraw(drawOpen);
} else if (hit.collider.tag == "book"){
if (PlayerCollisions.showedGJ){
canUncScream = true;
StartCoroutine(showPaintClue());
safe.SetActive(true);
}
} else if (hit.collider.tag == "safe"){
inputField.SetActive(true);
pwQs.SetActive(true);
}
}
}


}

public IEnumerator showClue1() //NOT SHOWING WHEN BOOK1 IS CLICKED
{
clue1.gameObject.SetActive(true);
yield return new WaitForSeconds(10);
clue1.gameObject.SetActive(false);
enableBatteries = true;
}

public IEnumerator showPaintClue(){
scream.SetActive(true);
yield return new WaitForSeconds(10);
scream.SetActive(false);
}

void addStuff()
{
if (enableBatteries)
{

if (battery1 != null && battery2 != null && battery3 != null)
battery1.SetActive(true);
battery2.SetActive(true);
battery3.SetActive(true);

}

}


}[/CODE]

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.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom