F
F
flanyaa2021-06-22 23:04:25
C++ / C#
flanyaa, 2021-06-22 23:04:25

How to make touch-movement of an object in a unit?

I need to be able to move the "Player" object with my finger right and left.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mixer1111, 2021-06-23
@Mixer1111

Line
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Returns the mouse coordinates in the world coordinates format to the mousePos variable.
And then, if you need to detect a mouse click on an object using void OnMouseDown(), and if it is that object, start moving. You will get something like this:

void OnMouseOver()
{
  if (<проверка, нужный ли тебе объект>)
  {
    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    <перемещение твоего объекта в позицию mousePos>
  }
}

(yes, if you do everything for the mouse, everything will work on the phone)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question