Good day everyone,
I’ve a question about touch input and using it to move my camera.
My goal is to move the camera, which shows everything from above, with touch. So if my finger swipes up in a value of 1, the camera swipes down in a value of 1. So you move it like moving the map in google maps.
This code is in the update-section of my camera.
if (Input.touchCount == 0)
{
hold = false;
}
if (!hold) //wenn noch nicht gehalten, dann
{
if (Input.touchCount == 1) //überprüfe, of ein kontakt
{
hold = true;
startPos = Camera.main.ScreenToViewportPoint(Input.touches[0].position);
}
else if (Input.touchCount == 2) //überprüfe, ob zwei kontakte (ZOOM)
{
}
else
{
}
}
else //wenn schon gehalten wird, dann
{
if (Input.touchCount == 1)
{
Vector2 MoveVector = new Vector2(startPos.x - Camera.main.ScreenToViewportPoint(Input.touches[0].position).x, startPos.y - Camera.main.ScreenToViewportPoint(Input.touches[0].position).y);
transform.Translate(MoveVector * Time.deltaTime * 20);
}
}
I know, this is maybe hard to understand what I want (because I’m too stupid to tell you correctly), but I’m very happy about every answer
Have a nice day dudes!