- Home /
Raycast doesn't work on Android(cardboard VR), but works in editor.
Hi, I'm stuck for three days now and I really need your help guys.
So the problem is that, raycast doesn't work on android(samsung s6) but works in editor(using Unity 5.2.3f1, and tried 5.2.2f1), so I can't solve it myself. Am I missing any option that has to be set? or is my code the problem? It used to work, but I believe I updated Unity and Carboard SDK and Simple code like this doesn't work anymore. I don't think it's problem of cardboard sdk, I tried setup a simple camera to shoot ray at gameobject and still didn't work.
RaycastHit hit;
// Update is called once per frame
void Update () {
Debug.DrawRay(gameObject.transform.position, gameObject.transform.forward * 10);
Physics.Raycast(gameObject.transform.position, gameObject.transform.forward, out hit);
if (hit.collider.tag == "target")
{
hit.collider.transform.Rotate(0, 90*Time.deltaTime, 0);
}
}
O$$anonymous$$ so it's definetly not a script fault.
I tried making a new project with copied asset and everything worked. Some internal/project issue.
in Raycast method call there is maxdistance parameter before out hit you are missing
Answer by Tom01098 · Nov 25, 2015 at 08:58 PM
There seems to be a bug with Unity, where if the editor is not visible on your computer, and you are running the game on your phone and they are linked, then no graphical changes actually happen on the phone. Maybe that is your issue?
Answer by Evaldas · Nov 27, 2015 at 10:25 AM
Can't really tell mate, It's must be Unity's bug. Don't know what it is, but the bug has something to do with physics, no collisions worked also in Android build. They weren't linked.
Answer by megatonmedia · Jul 09, 2019 at 04:26 AM
I just ran into into this bug in Unity 2018 and 2019. If you have multiple EventSystem scripts in your scene. It confuses the VR Event system and the whole thing just stops working. It also breaks in the editor after you do an android build and it will stay broken until you reload your scene.
I'm replying to an old issue as this was high in my google search results and there are very few other results. Hopefully this will help a couple of people.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Using raycasts to move a game object toward touch point. 0 Answers
Distribute terrain in zones 3 Answers
Things to do to port game made for iOS in Unity to Android? 2 Answers
Unity 3d - connect android to pc via usb 0 Answers