Sorry for the cross-post, but I didn’t see this forum till now and it is way more suitable
I have a raycast which checks if a linerenderer hits an object.
It works if I build it under Windows or Mac standalone. It works in the editor under Android but it doesn’t work when built under Android.
Anyone got any suggestions? I have searched for this issue and I have found several threads talking about colliders not working due to physics time issues, but my raycasts CANNOT MISS! The raycast is always aimed directly at the target, and often the target is not moving.
I have tried running the raycast 5 times each time instead of once, no effect.
The code is here but remember it works all the time except when deployed on Android
RaycastHit2D hit = Physics2D.Raycast(btp, transform.up, LaserRange);
if (hit)
{
Destroy(hit.collider.gameObject);
}
I am using an Huawei Honor 6 running Android 4.4.2. If you need more info just ask. I am not an Android expert, so be kind…
Hi. In answer to your question on my post, my problem was that the raycast object wasn’t attached to a camera in my scene, it was attached to the OVR controller (for Samsung Gear VR), and because I was rendering monoscopically the app was ignoring the OVR controller and just rendering one of the cameras (the right one I think). When I attached it to my camera, rather than the controller, it worked straight away, both in the editor and in the app.
The only thing that I can suggest, as I am not an expert, is to try what happens to the collider, so rather than
I might be confusing myself between raycast and raycast2d, and I only suggested it as that is what I did with my solution and it worked, although my app was in 3d space and not 2d space.
The LayerMask is optional. The code worked without, but I added it for efficiency.
Not sure if that is the problem, but the main difference is that I use the Physics.Raycast directly in the if clause, while in your code it is first saved to a RaycastHit variable.