Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class RenderTextureTest : MonoBehaviour
- {
- public Transform quad;
- public Camera ingameCamera;
- public bool checkObstruction;
- void Start ()
- {
- UICamera.raycastConversion = RenderTextureRaycastConversion;
- }
- public Vector3 RenderTextureRaycastConversion(Vector3 screenPoint)
- {
- Ray ray = ingameCamera.ScreenPointToRay(screenPoint);
- Debug.DrawRay(ray.origin, ray.direction * 100, Color.green);
- // raycast to the quad plane
- Plane plane = new Plane(quad.transform.forward, quad.transform.position);
- float enter;
- if (!plane.Raycast(ray, out enter))
- return new Vector3(float.NaN, float.NaN, float.NaN);
- Vector3 projectionPoint = ray.origin + ray.direction * enter;
- if (checkObstruction)
- {
- if (Physics.Raycast(ray, enter - 0.1f))
- return new Vector3(float.NaN, float.NaN, float.NaN);
- }
- Debug.DrawLine(Vector3.zero, projectionPoint, Color.red);
- // transform to quad space
- Vector3 quadSpace = quad.transform.InverseTransformPoint(projectionPoint);
- Vector3 finalPoint = quadSpace + new Vector3(0.5f, 0.5f, 0);
- return finalPoint;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment