Why is input mouse clicking not working on WebGL build?
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:
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);
}
}
}
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.