Touch Input System having problems with joystick

So… im new to unity… im having this problem: I have a seperate camera look script and a different joystick to more player. And i have this touchfield script where it gets the touch value. So when i first touch the screen then move joystick, its fine. Moving joystick doesnt move the screen and screen move is smooth. When i first move the joystick then move the screen, its fine too. But when i first move the screen, then move the joystick, then leave the screen then touch it again to move, while still moving the joystick, the screen doesnt move. Instead the place where im touching the joystick, it starts moving the screen. I have tried so many different ways, i cant seem to find the logic behind how to do this. This is the touchfield script im using:

    private GameObject player;
    public Vector2 TouchDist;
    public bool Pressed;
    private PlayerControl firstPerson;
    private PlayerMovement playerMovement;
    private demo demo_;
    public int index;
    public bool prevMoved;

    public void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player");
        demo_ = player.GetComponent<demo>(); // dont mind this demo part
        firstPerson = player.GetComponent<PlayerControl>();
        playerMovement = player.GetComponent<PlayerMovement>();
        prevMoved = false;
    }

    private void OnEnable()
    {
        EnhancedTouchSupport.Enable();
    }

    private void OnDisable()
    {
        EnhancedTouchSupport.Disable();
    }

    void Update()
    {
        if(!Pressed)
        {
            if (firstPerson.input.x != 0 || firstPerson.input.y != 0)
                prevMoved = true;
            else
                prevMoved = false;
        }
        if (Pressed)
        {
            if(prevMoved)
                TouchDist = Touchscreen.current.touches[1].delta.ReadValue();
            else
                TouchDist = Touchscreen.current.touches[0].delta.ReadValue();
        }
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        Pressed = true;
        demo_.touchFieldIndex = index;
    }


    public void OnPointerUp(PointerEventData eventData)
    {
        Pressed = false;
        TouchDist.x = 0;
        TouchDist.y = 0;
    }

Welcome to the forums. So you know, you should use code-tags when posting code and not plain text. You can edit your post.

I’m not able to help you with your post unfortunately.

Sorry about it! This was my first forum. I have changed it.

1 Like

New
Someone helped me find the fix: Use the OnDrag method instead of touch inputs, it works better.