FINDING MOUSE COORDINATES REACT CODE
The code works at this resolution (with a raw image width and height value of 170). I'm also not sure how the "Canvas Scaler" might play a role in it.įor example, currently in my Unity editor my screen resolution is somewhere around 800 x 600. I just can't think of the math formula to convert it based on screen resolution (or if there's a way to reference the image size).
![finding mouse coordinates react finding mouse coordinates react](https://i.stack.imgur.com/RhZJQ.png)
So that "170" value number in my code needs to fluctuate depending on the pixel width and height of the raw image.
![finding mouse coordinates react finding mouse coordinates react](https://i0.wp.com/reactscript.com/wp-content/uploads/2017/05/React-Cursor-Position-Component.png)
I'm fairly certain it has to do with the screen resolution actually. I'm not about to write code here as it's offtopic to OP.Ĭlick to expand.Well the calculations run every time the user clicks on the minimap, so that shouldn't be a problem. If you need to transform world coord->rendertexture camera->rawimage->screen coords on UI, then reverse all 4 steps.
![finding mouse coordinates react finding mouse coordinates react](https://www.codegrepper.com/codeimages/copy-textarea-to-clipboard-in-reactjs.png)
From mousePosition into absolute coordinates of rawImage(Input.mousePosition - corners from above).Let's say we're making minimap with rendertexture draw on rawimage+its camera and you need to click on it to select something in world you would need to make several transformations: