- Home /
Question by
Mmocraft · Jun 07, 2021 at 10:31 PM ·
joysticktouch controlsphone
How to Spawn joistick at touch position, taking same touch as input?
Hey, im using unitys Joystick pack, and i want my Joystick to show at the touched point, when i touch the screen in a certain area (this is working). Now if i move my finger, the joystick should take this touch movement (that spawned it) as its input. But if i set the joystick active after the touch has begone, it doesnt recognize the touch move. Here is my code:
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
Vector2 pos = touch.position;
if(pos.x < width && pos.y < height && !joystick.gameObject.activeSelf)
{
joystick.gameObject.transform.position = new Vector3(pos.x, pos.y, 0);
joystick.gameObject.SetActive(true);
}
}
else
{
joystick.gameObject.SetActive(false);
}
I thought the easiest way would be to somehow access the joysticks touch and set it to the already existing touch. But i have no idea if this is possible. Does anyone have an idea, how i could solve this problem?
Comment