- Home /
Mouse Position to array
For the life of me I cannot get the mouse position to translate to my array. I have an array, it is 2d, 8x8 array, the array works fine i've tested that. But when I try to make the mouse position correlate I cannot get the right division or something.
mousecol=Mathf.RoundToInt((Mathf.RoundToInt(Input.mousePosition.y))/91); mouserow=Mathf.RoundToInt((Mathf.RoundToInt(Input.mousePosition.x))/163);
That is what I have for my mouse correlation, but as I said its not working. It never puts it in the right space, and I cannot figure out why.
Answer by ChrisButler · Nov 16, 2012 at 04:35 AM
I managed to solve the problem, the Y counted backwards to the way I thought it should be counting, So I just used a case structure to swap them around. Dirty but it works.
Answer by kramcomposer · Nov 15, 2012 at 11:33 PM
use Mathf.FloorToInt; you'll get more consistent results
also y 0 means top of screen, in other words if your screen resolution is 1920*1080
mousePosition.y = 0 //Top of screen
mousePosition.y = 540 //Middle of screen
mousePosition.y = 1080 //Bottom of screen
Unfortunately that doesn't fix my problem, it places it in the wrong spot. Even knowing the resolution has not helped.
Your answer
Follow this Question
Related Questions
Rotate 3rd person Character according to mouse position 0 Answers
How to get mouse position in World Space when in Editor Mode 1 Answer
How can I save MouseLook position in this script ? 0 Answers
Why can't i use these arrays to access positions and objects properties? Please help! 3 Answers
how to make the object position related to the screen 2 Answers