Move character until true
Hello. I'm trying to make an auto-walk function like in MMORPGs.
In final it must be like this: when I click a middle mouse button, my character begins to walk straight until I click the same button again. I finished my WASD movement and can't figure out how to implement the same code in my problem. What should I do?
 public class UserMovement : MonoBehaviour
 {
      public float currentSpeed;
 void Start()
     {
           CharacterController controller =(CharacterController)GetComponent(typeof(CharacterController));
     }
 
 void Update()
     {
  if (grounded)
         {
             //wasd movement with mouse look (didn't include mouse part here)
             moveDirection = new Vector3(0, 0, Input.GetAxisRaw("Vertical"));
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *=  currentSpeed * Time.deltaTime;
             controller.Move((moveDirection) );
 
  if (Input.GetMouseButtonDown(2))
             {
               // Please, move forward constantly until I press this button again!
             }
         }
     }
 }
 
              
               Comment
              
 
               
              Never$$anonymous$$d guys, I'm just feeling myself drunk or something... Here is the solution:
 if (is$$anonymous$$oving)
         {
             transform.Translate(Vector3.forward * (currentSpeed * Time.deltaTime));
         }
         if (Input.Get$$anonymous$$ouseButtonDown(2))
             is$$anonymous$$oving = !is$$anonymous$$oving ? true : false;
                 Your answer