- Home /
Raycast through render texture from a graphic raycaster?
Hello all.
I am trying to make an interactive game window that's on a canvas. When I try to look up any documentation on doing this, 9 times out of 10 it is for a player camera in Unity3D.
My problem is that I'm using GraphicRaycaster.Raycast, which doesn't have access to RaycastHit.TextureCoord, unlike Physics.Raycast. So I'm not quite sure how to get a position to send a ray from my game cam. The closest thing I've seen to getting a position I need is RectTransformUtility.ScreenPointToLocalPointInRectangle, but it doesn't seem to be giving me the correct numbers.
I will keep testing and researching. Will post my results here if I find anything. Any help would be much appreciated!
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Raycaster : MonoBehaviour
{
public GraphicRaycaster mainUi;
public EventSystem ES;
PointerEventData eventData;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
//Maincam Raycast
List<RaycastResult> hits = new List<RaycastResult>();
eventData = new PointerEventData(ES);
eventData.position = Input.mousePosition;
mainUi.Raycast(eventData, hits);
foreach (RaycastResult hit in hits)
{
if (hit.gameObject.tag == "GameScreen")
{
//Gamecam Raycast
}
}
}
}
}
Your answer
Follow this Question
Related Questions
UI interaction via RenderTexture 0 Answers
RenderTexture does not render canvas image. 0 Answers
How to use both NGUI widgets and unity UI 0 Answers
Render Textures and Raycasting 0 Answers
How to prioritize Raycast collisions over Trigger Events? 1 Answer