I
I
igorloadgame2021-04-22 15:24:52
Unity
igorloadgame, 2021-04-22 15:24:52

How to move an object when touching the screen?

How to move an object when touching the screen, i.e. to click on the right side of the screen and the car smoothly goes to the right?

if (Input.touchCount > 0)
        {
            if (lTouchUnt.x < Screen.width / 2)
            {
                player.transform.position = new Vector3(player.transform.position.x + Speed, 1.159f, 0) * carSpeed * Time.deltaTime;
            }
            else
            {
                player.transform.position = new Vector3(player.transform.position.x - Speed, 1.159f, 0) * carSpeed * Time.deltaTime;
            }
        }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question