How do I keep my value, when it reset?

void Update()
{
Vector3 ya = joystick.Direction;
x = joystick.Horizontal;
forceSlider.value = force;
if (Input.GetMouseButton(1))
{
force += 5f;

        }
       
        if (Input.GetMouseButtonUp(1))
        {
            //The ya variable is always reset when I let go of the joystick
            //How do I keep the the previous value when I let go of the Joystick??

           
             rb.AddForce(x,0,0 * force);
            force = 0f;
        }
    }

The x values always reset when I let go of the joystick, how do I keep the the previous value when I let go of the Joystick??

Hi @nugehood, you could just define ya outside of your Update function and add an if condition when you are setting them… like the following:

  Vector3 ya = Vector3.zero;
  
  void Update()
     {
             if(joystick.Direction != Vector3.zero)
             { ya = joystick.Direction; }
             
             if(joystick.Horizontal != 0)
             { x = joystick.Horizontal; }

Unless I’m not understanding what you’re trying to do…