R
R
Roman2018-05-01 09:41:02
C++ / C#
Roman, 2018-05-01 09:41:02

How to check button click in unity?

Hello!
How in a unit through a separate method (if there is one, of course) to receive a button press (LMB, RMB, W, A, etc.)? For through Update () to do all this is a little ... expensive.
And one more question:
How is it "correct" (without additional loads) to pass a reference to an object? Is it enough to make it public and just drag it with the mouse? Or is it better to find it by name in Start()?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavlo Ponomarenko, 2018-05-01
@ananas_roma

1. IPointerClickHandler + PointerEventData.button
2. Quite right - DI Container, for example Zenject. If not, then drag with the mouse. Find is no doubt very slow. Even without going through the hierarchy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question