OnMouseDown w/ Multiple Cameras Doesn't Work Right

So I have two cameras. One that is doing a render texture to a target, and one that functions as the main camera. I have OnMouseDown events, in a script that that is attached to every object that they will be called (pieces in a match-3 puzzler), that were working perfectly before adding the second camera, and now they don’t work at all. If I put the render target camera over the area where those events would occur, it starts working again.

Clearly the OnMouseDown function is favoring the second camera (render target camera) when checking OnMouseDown events. I don’t want this to happen. How do I switch it from second camera to main camera?

I’ve tried switching the cameras functions around (aka making main the render and vice versa) and it always favors the render target camera. I’ve tried changing depth, layers, culling masks, and pretty much every other option in the camera editor menu, but to no avail.

I also stumbled upon this bug. I have 2 cameras, one which renders in a texture (TexCam), the other doing the main rendering (MainCam). Here is the workaround I found :

  1. Disable TexCam
  2. Create a C# script :

`

public class TexCamHack : MonoBehaviour {

    public Camera textureCamera;
 
 void OnPreRender() {
 textureCamera.Render(); 
 }
}

`
3. Add the script to MainCam and assign TexCam to the field textureCamera

I solved this by using the “MainCamera” tag, i.e.

mainCam.tag=“MinorCam”;
secondCam.tag=“MainCamera”;

var CAM1 : GameObject;

car CAM2 : GAmeObject;

function OnMouseDown () {

 CAM1.// blah blah

 CAM2.//Blah Blah
}

Attach this to the rendered object that you want to click

I ended up changing the code in my master script to do this, which essentially ports all the OnMouse events to manual raycasting.

camRay = boardCamera.ScreenPointToRay(Input.mousePosition);
	if(Physics.Raycast(camRay, out hit, 100))
	{
		if(hit.collider.gameObject.layer == 8)
		{
			currentPiece = hit.collider.GetComponent<PieceScript>();
			if(currentPiece != lastPiece)
				currentPiece.MouseEnter();
			if(currentPiece != lastPiece && lastPiece != null)
			{
				lastPiece.MouseExit();
			}
			lastPiece = currentPiece;
			if(Input.GetMouseButton(0))
				currentPiece.MouseDrag();
			if(Input.GetMouseButtonDown(0))
				currentPiece.MouseDown();
			if(Input.GetMouseButtonUp(0))
				currentPiece.MouseUp();
		}
	}