P
P
polyakovyevgeniy2017-04-01 20:19:37
Unity
polyakovyevgeniy, 2017-04-01 20:19:37

How to determine which mouse button was pressed?

There is a script which is hung up on object. The script has an OnMouseDown() method. It fires when you click on the object's collider, but how do you determine which mouse button was used to click?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2017-04-01
@polyakovyevgeniy

Replace it with Update with Input check
As an example in the documentation)
https://docs.unity3d.com/ScriptReference/Input.Get...
And send a ray to the collider, check which object it hit.

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, 100))
            print("Hit something!");

Another option is to read about the new interface and how to implement it using it (here you can google a lot yourself)
https://docs.unity3d.com/ScriptReference/EventSyst...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question