Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Raycast in editor working fine, but when built to android doesn't work

Discussion in 'Physics' started by Woyzeck1, Jul 6, 2015.

  1. Woyzeck1

    Woyzeck1

    Joined:
    Jan 15, 2013
    Posts:
    10
    Hi there,

    I am having a really strange experience. I am trying to build a Gear VR app, that allows a user to look at a menu, and after a certain amount of time, a raycast event tells the app to enable a gameobject. In the editor, this works absolutley fine, but within the app it never seems to work. i don't know whether it is something to do with the plugins, or whether it is my code, but I am pulling my hair out a bit here!

    Code (CSharp):
    1. void cameraRayCast()
    2.     {
    3.         RaycastHit hit;
    4.         Ray ray = new Ray(transform.position, transform.forward);
    5.         Vector3 fwd = transform.TransformDirection(Vector3.forward);
    6.  
    7.    
    8.  
    9.  
    10.    
    11.             if (firstTrigger.Raycast(ray, out hit, Mathf.Infinity))
    12.             {
    13.  
    14.                 gm.bp1 = true;
    15.                 Debug.DrawLine(transform.position, transform.forward, Color.red);
    16.             }
    17.  
    18.             else
    19.             {
    20.  
    21.                 gm.bp1 = false;
    22.                 gm.bp1time = 4.0f;
    23.  
    24.             }
    The idea is that the user has to look at the collider for a certain amount of time for it to trigger.

    In the gm script that is referenced, in the update this is called:

    Code (CSharp):
    1.    if (bp1)
    2.         {
    3.             bp1time = bp1time - Time.deltaTime;
    4.             timer = bp1time;
    5.      
    6.             Debug.Log("bp1");
    7.         }
    8.  
    9. if (timer <= dwellTime)
    10.         {
    11.  
    12.             if (bp1)
    13.             {
    14.  
    15.                 bp1 = false;
    16.                 barPlane1.startFade = true;
    17.                 Debug.Log("bp1 timer change");
    18.                 Invoke("enableSphere1", timerSphere);
    19.              
    20.             }
    Any and all suggestions are welcome. I've tried in Unity 5.1, and Unity 4, and I also using the OVR controller, but I have created succesful raycast events using that in the past.

    Thanks,

    Tom


    EDIT: Solved my problem. I had attached the raycast to the camera rig, and attaching it to one of my cameras solved the problem.
     
    Last edited: Jul 6, 2015
  2. peaveyyyy

    peaveyyyy

    Joined:
    Mar 10, 2014
    Posts:
    14
  3. m_plqp2

    m_plqp2

    Joined:
    Jun 22, 2018
    Posts:
    2
    I have the same problem
     
  4. DoYourBest

    DoYourBest

    Joined:
    Sep 4, 2019
    Posts:
    1
    The solutoin worked for me the script that ocntains the raycast has to be on the camara no ona parent object