Movement With Time?

When I click the mouse, my character will move 2 seconds. How can i do it?

Time.time or Time.deltaTime should do the trick it been the awhile since i used either one for moment so i could tell you which one would be better use although you do might want to stick them in FixedUpdate

You could create a timer…

If timer > 0, move forward and timer -= Time.deltaTime.

When player touches the button, just set timer = 2.0;

//hmmm its very easy

//total time for running
public float runningTime = 5.0f;

//running speed
public float runningSpeed = 5.0f;

//current remaining time
private float currentTime;

//boolean to turn on off running option
private bool isRun = false;

//x position for vector
private float xPosition;

void Update() {
    if(isRun) {
       if(currnetTime>=runningTime) {
            isRun = false;
            currentTime = 0;
            
       }
       else {
          currentTime += time.deltaTime;
          xPosition +=time.deltaTime*runningSpeed;
       }
    }
}

void OnGUI() {
    if(GUI.Button(new Rect(0,0,100,100), "Run")) {
       isRun = true;
    }
}