Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    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.   RaycastHit2D hit = Physics2D.Raycast(pos,;
    2.   if (hit.collider != null) {
    3.   //do stuff here
    4.   Debug.Log(;
    6.   }
    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?