Hello, i’m a very beginner to unity and C# but i’m trying to create a little game, where the mouse drag the camera by pressing down. There is object on the map that I want to click on when its asked to, but when i click on the screen to drag the camera, it also select the object, wich i don’t want to.
So my question is :How to click on an object while the mouse is not moving ?
An example would be easier to understand so what I want is exactly like the system in stellarium https://stellarium-web.org/ where you can drag the sky by clicking even when the mouse is on a constellation, but if you single click on the constellation, it select it.
I hope my english is understandable
The code should be like that
public class OnMouseDown : MonoBehaviour
{
void OnMouseDown()
{
if(Input.GetMouseButton(0) && the mouse moves)
{
do nothing
}
if(Input.GetMouseButton(0) && the mouse didn’t moves)
{
do something
}
Usually this is done by keeping track of if you are in “clicking” or “dragging” mode.
You would start in “neutral” mode until the mouse button went down, then you record where it went down but do nothing.
When the button is held down, if the mouse moves more than a certain amount, you switch into dragging mode, and know you cannot click anymore. From that point you process drag intentions.
When the button is released you would decide if you are still in clicking mode or not and signal that user intention.