- Home /
Click on Canvas in a render texture
Here is my setup : i got a main canvas, which contains 3 render texture (on raw image).
I want to click on them, and interact with the content display by the render texture
In my case, each side of the cubes are a canvas. Click on buttons on the canvas made him rotate to the left, right, top or bottom to display an other canvas.
Each cube got its own camera. And each camera display only its cube.
I try to do that because i want to make a particular effect that is not possible to get if i directly display the 3 cubes.
I made basic snapshot, don't know if I made myself clear. Tell me if you need more informations or if you don't understand my problem.
I found this : http://answers.unity3d.com/questions/1018336/is-there-a-way-to-click-on-a-render-texture-to-sel.html It does exactly what I want, but without canvas :(
I tried something with the event system RaycastAll, but that's a mess, I used viewport coordinate to prevent ratio issues between the cameras, but it's quite difficult to display. I'm not even sure if its possible ...
I'm able to know which render texture is under my mouse (that's the easy part), but when i try to send a pointer event through the second camera (according to the right renderTexture and with some maths to adapt the ratio), that's just a mess ...
Tell me if you have some clue or any ideas !
have you tried using "https://docs.unity3d.com/ScriptReference/RaycastHit-textureCoord.html" to get the mouse position passed to your render texture camera?I'd think you could simply scale that value by the camera screen size to get your "second screen" mouse position.
Hi, thanks for the advice. I only use canvas on my scene, so i can't use any physic raycast. I have to use Event system Raycast, which never return a RaycastHit ... (https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem.RaycastAll.html)
I have to put every canvas on a plane and i'll be able to use physic raycast, but that's not the behavior I'm looking for right now ...
You can manually call the physics raycast whenever you want. Even after your event system detects a hit. (though that does seem a bit inefficient, not sure how else to get those texture uv coords)
Not sure how that function I mentioned works with canvases, but it's easy to overlay a canvas with an (un-rendered) quad mesh.
$$anonymous$$aybe i can ask another question, easier to understand than my huge post.
Is it possible to make an EventSystem.RaycastAll (https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem.RaycastAll.html), thought a camera that isn't the main one and not displayed on screen.
In fact, i want to create a fake PointerEventData by a second camera, which isn't display or visible (it just render a texture)