Hi to everyone, first of all sorry for my english. I try to get a position of mouse where i hit in view. But not pixel position like “input.mouseposition”. I tried that. it gave me the pixel position. i need 3d coordinates where i hit in scene. could you please give me a simple sample script about this ?
Use the Camera.ScreenPointToRay() function. You just send in the screen coordinates and it gives you a ray shooting into the world from that point. You can then use that ray to do collision tests to work out what you have clicked on.
thanks for answer i tried what you say but i couldn’t success
could you give me some detail information about this ? for example if you can write me a simple script from beginning to end may it be wonderfull for me
thank you
I can write out the steps for you, I don’t want to write out the whole script as I don’t have a chance to test it right now and don’t want to steer you in the wrong direction.
If you have a look at the example in the documentation for Input.mousePosition you actually have most of the code you need to do this. The example there puts the function you would have been using to get the mouse screen coordinates into the Camera.ScreenPointToRay() function I suggested. This function returns a bool to let you know if it hit anything or not.
If you look at the reference for Physics.Raycast() you can use the last variation of the function on that page to get the position where the ray hits an object.
Aside from writing your code for you, I don’t know how much more I can explain, and if I wrote all your code, well it wouldn’t be yours then would it? ![]()
And I still maintain that the best way to learn to code is trial and error. ![]()
Agreed. I understand the need for a push in the right direction, and you do need help to get going at first, but learning how to use the documentation to get that trial and error method right is invaluable.
Thanks for helps i’ll try ![]()