A
A
Alexander Interesting2021-08-08 17:44:37
C++ / C#
Alexander Interesting, 2021-08-08 17:44:37

How to get mouse coordinates relative to the world?

How to get mouse position on stage, I use:

Vector2 screenPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Vector2 worldPosition = Camera.main.ScreenToWorldPoint(screenPosition);
Debug.Log(worldPosition);

I click on an object whose coordinates are "56.1 98"
And the result of the code: (6.9, 55.2)
Why is that? And how to do it right?

Unity version: 2020.3.15f2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nekit Medvedev, 2021-08-09
@NIKROTOS

You write to screenPosition the deviation of the mouse from 0, at the moment. What moves the mouse? If with a cursor, then take its coordinates, if there is no cursor ... I don’t know why this might be needed, you can just put a dummy.
It is quite convenient for the cursor to move the trigger.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question