This suggests some things.
First I use EventSystems to get the mouse clicks. This is not a requirement, it can be easily changed (by you, though ^^). To properly configure it, you will need an EventSystem in your scene (if you have a user interface, you probably already have it).
Secondly, you need to attach the PhysicsRaycaster component to the main camera (the camera that the player sees).
Finally, in a GameObject that contains a renderer for the rendering texture (I used a simple quad), you apply the script below and assign the appropriate camera.
using UnityEngine; using UnityEngine.EventSystems; //i chose box collider because its cheap [RequireComponent(typeof(BoxCollider))] public class RenderTextureRaycaster : MonoBehaviour, IPointerDownHandler { //assign in inspector public Camera portalExit; BoxCollider portal; Vector3 portalExitSize; void Start() { portal = GetComponent<BoxCollider>(); //this is the target camera resolution, idk if there is another way to get it. portalExitSize = new Vector3(portalExit.targetTexture.width, portalExit.targetTexture.height, 0); } public void OnPointerDown(PointerEventData eventData) { //the click in world space Vector3 worldClick = eventData.pointerCurrentRaycast.worldPosition; //transformed into local space Vector3 localClick = transform.InverseTransformPoint(worldClick); //since the origin of the collider is in its center, we need to offset it by half its size to get it realtive to bottom left Vector3 textureClick = localClick + portal.size / 2; //now we scale it up by the actual texture size which equals to the "camera resoution" Vector3 rayOriginInCameraSpace = Vector3.Scale(textureClick, portalExitSize); //with this knowledge we can creata a ray. Ray portaledRay = portalExit.ScreenPointToRay(rayOriginInCameraSpace ); RaycastHit raycastHit; //and cast it. if (Physics.Raycast(portaledRay, out raycastHit)) { Debug.DrawLine(portaledRay.origin, raycastHit.point, Color.blue, 4); } else { Debug.DrawRay(portaledRay.origin, portaledRay.direction * 100, Color.red, 4); } } }
edit: the above is probably a bit verbose, you can easily save it if you like some liners, just to show how it works. also please, consider this only as a proof of concept, it has not been fully tested.
yes
source share