There is a set of gameobjects that will work as buttons. The box collider hangs on them and the pointclick trigger is also hung on the code (it calls the function with parameters, the parameters are different for each "button"). And then the question arises. How to bring this all into working condition so that the trigger will trigger on a click?

How to make the event work?

  • I think here.stackoverflow.com/a/498568/191482 the first way is exactly what you need - Alexey Shimansky
  • I read to:> Only instead of Input.mousePosition to track the touch ... I did not understand further ((((. 1) How to catch a click to trigger the trigger. 2) I didn’t quite understand how to handle different clicks. (My camera movement is tied to TouchPhase. Moved) - Slimper
  • Plus, I don’t have a UI element - Slimper

1 answer 1

It is not entirely clear what the problem is. The activation of the object is solved by the standard methods of the unit dismantled in the documentation.

if(Input.GetTouch(0).phase == TouchPhase.Began) // если есть тач { hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Vector2.zero);// то делаем рейкаст от координаты тача if(hit.collider!= null && объект удовлетворяет условиям )// если во чтонибудь попали { DoStuff();// делаем что нам нужно } } 
  • Yes, I just thought that the event trigger (pointerclick) will work on 2d sprite, and it only works with ui. That this was a cant ... Thank you. (Just the question arose of separating pressing and moving the camera)) - Slimper