- Home /
RayCast in WebGL not working
Hi,
I'm having an issue with RayCasts not working in a WebGL build. The issue exists in both Chrome and Firefox. It works fine in the editor and in a PC-standalone build.
I'm using Unity version 2017.4.0f1 Personal.
I'm using the following code:
void Update()
{
Ray detectobject = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(detectobject.origin, detectobject.direction * 10, Color.yellow);
Physics.Raycast(detectobject, out hit, 100);
if (Input.GetButtonDown("Fire1") && hit.transform != null && hit.transform.tag == "Territory" && !EventSystem.current.IsPointerOverGameObject())
{
SelectTerritory();
}
if (Input.GetButtonDown("Fire2") && hit.transform != null && hit.transform.tag == "Territory" && !EventSystem.current.IsPointerOverGameObject() && selectedTerritory != null && selectedTerritory.GetComponent<Territory>().unitList.Count > 0)
{
SelectTargetTerritory();
}
}
Any help would be greatly appreciated.
Regards, Rob
Hello @AkaBrokenarrow Its a good idea to start looking before asking as you may well find either the trail towards the answer, or indeed the actual answer you are looking for... I would suggest starting from here and seeing if your issue is covered at all by these common mistakes discussed. Cheers bud, hope it helps in narrowing down the solution for you :)
https://answers.unity.com/questions/788300/why-is-this-raycast-not-working.html
Thanks for the answer; however I already extensively searched the net for similar issues. The post closest to my issue is https://forum.unity.com/threads/chrome-53-breaks-raycasting-in-webgl.429722/, but in my case, raycast doesn't work in ANY browser.
Hmm strange one. Okay bud. Sorry that didn't yield anything good for you.
Have you tried going back a few steps and creating a simple scene with an abject using the raycast and something for it to hit and test building this to webgl to see if that works ? If so, your code will be the issue Vs UnityWebGl build .
For future people having an unrelated issue: I was having this problem and stumbled onto this page. Turns out it was silly and I needed to enable the USE_PHYSICS2D define per platform and I had only done it for PC I was originally testing on.
Answer by rob_ice · May 15, 2018 at 02:10 PM
Same issue here, has anyone been able to fix it by any means? Have noticed a few people reporting the same issue recently?
Answer by Bslashingu · May 23, 2018 at 02:52 PM
Having this same issue in 2017.4.2f2 in WebGL, driving us nuts
Answer by atreyu64 · Dec 12, 2018 at 12:08 AM
Same issue in 2017.4.0f1. Do I have to download a newer version to fix it ? If so, which version exactly ?
Thanks !
Answer by garasouleima01 · Jul 07, 2019 at 09:20 PM
same problem in 2018.3..14f1 any solution please !?
Your answer
Follow this Question
Related Questions
Physics.Raycasy not really using Layermask? 1 Answer
Having a RaycastHit event create a component? 1 Answer
thousands of raycasts in nested for loop 0 Answers
Physics2D.Raycast Reflect issue 1 Answer