OnMouseDrag or Raycast through RenderTexture

I have an object I am using the OnMouseDrag function to rotate using the cursor, but this doesn’t work for obvious reasons through a RenderTexture.

My hope is that there is another way to do this with the same effect through the RenderTexture so I can add this to my UI.

I found a script online which is supposedly able to RayCast through a rendertexture through the camera to the other side, but this requires the Physics components, which don’t work on UI objects.

This is the script I found:

using UnityEngine;
using System.Collections;

public class RaycastRendertexture : MonoBehaviour
{

    public Camera portalCamera;

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                Debug.Log(hit.collider.gameObject);

                var localPoint = hit.textureCoord;

                Ray portalRay = portalCamera.ScreenPointToRay(new Vector2(localPoint.x * portalCamera.pixelWidth, localPoint.y * portalCamera.pixelHeight));
                RaycastHit portalHit;

                if (Physics.Raycast(portalRay, out portalHit))
                {
                    Debug.Log(portalHit.collider.gameObject);
                }
            }
        }
    }
}

The code for my object is here:

using UnityEngine;
using System.Collections;

public class ObjectRotate : MonoBehaviour
{
    public float torque = 10.0f;
    private float baseAngle = 0.0f;
    public Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    void OnMouseDrag()
    {
        rb.AddTorque(Vector3.up * torque * -Input.GetAxis("Mouse X"));

        rb.AddTorque(Vector3.right * torque * Input.GetAxis("Mouse Y"));
    }
}

Bump