Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Raycast only hitting collider on first camera and not second one

Discussion in 'Scripting' started by CorWilson, May 13, 2016.

  1. CorWilson


    Oct 3, 2012
    In my game, there are two screens each represented by two camer. The second camera holds the displays that will read touch input and have interactions. Both cameras look at the same coordinates, but using a layer system, there are exclusive rendering layers for each camera. I use the following to read touch input for objects there:

    Code (csharp):
    1. Vector3 pos = cam2.ScreenToWorldPoint(Input.mousePosition);
    2.   RaycastHit2D hit = Physics2D.Raycast(pos,;
    3.   if (hit.collider != null) {
    4.   //do stuff here
    5.   Debug.Log(;
    7.   }
    This is where the problem occurs. When I attempt to touch the object on the second camera, no feedback returns. However, if I touch the same area on the first camera, the Debug shows up. Apparently, the raycast seems to be working on cam1, despite me referencing cam2. In addition, even if I disable the cam1 object entirely and use touch on its Game view, I still get touch debugs messages from it as if it's still there. So the real problem here is, why is the touch raycast not working for on the second camera. The second camera is the only area where any touch input will be read during gameplay, so it's valuable if this works.
    Last edited: May 13, 2016
  2. Rebaken-Enterprises


    Nov 17, 2014
    Any luck with this?