Dynamic change of the speed by guibutton

Hello

I have a functional script based on ITWEEN.

I would want to make 3 guibutton to change dynamically the speed by step of 10.

One to increase the speed of + 10 by click

one to decrease the speed of - 10 by click

one to put back the speed to the initial velocity of the script

Thank you for your help

#pragma strict 
public var target_Path1 : GameObject; 
public var time = 10.0;               
public var target : Transform ; 



private var tabt : Transform[];
 private var running = false; 
 private var paused = false;
 private var fraction = 0.0; 
 
 function SetPath (pathObject : GameObject){
     var id : int = 0;
     tabt =null;
     tabt = new Transform[pathObject.transform.childCount];
     for(var child: Transform in pathObject.transform)     {
            tabt[id++] = child.transform;
                 }
  WalkThePath();
                                           }
  
 
 
 function WalkThePath() {    
 paused = false;
 running = true;
 fraction = 0.08;  

  while (running) {
         transform.position = iTween.PointOnPath(tabt, fraction);
         
 if (!paused)
          fraction += Time.deltaTime / time;
 if (fraction > 1.0) fraction = 0.0; 
 

        var futurePos = iTween.PointOnPath(tabt, fraction + 0.02); 
        transform.LookAt(target);  
               yield;
                   } 
                      }
                   





function Start()
    {
           SetPath(target_Path1);    
    } 
    
   
     
              
function OnGUI(){
    if(GUI.Button(Rect(290,80,100,20), "commencer"))    
    {
           SetPath(target_Path1);    
    }    
   
   
     if(GUI.Button(Rect(390,80,100,20), "Pause"))    
     {  
           paused = true;    
     }     
     
     
     if(GUI.Button(Rect(490,80,100,20), "Reprise"))    
     {
            paused = false;    
     }     
     
     if(GUI.Button(Rect(390,100,120,20), "Reculer par étape")) 
     {       
           fraction -= 0.2 / time; 
           if (fraction < 0.0) fraction = 0.0;   
     }    
     
     
     
     if(GUI.Button(Rect(510,100,120,20), "Avancer par étape")) 
     {       
           fraction += 0.2 / time; 
           if (fraction < 0.0) fraction = 0.0;   
     }    
     
       if(GUI.Button(Rect(590,80,100,20), "Stop"))    
      {
          running = false;    
      }
          
          
          
// Here the 3 buttons for Increase or decrease by step 10, or put back to the initial speed       




      if(GUI.Button(Rect(590,120,100,20), "Speed  + 10 "))    
      {
          // ??????????????   
      }
      
      if(GUI.Button(Rect(590,140,100,20), "Speed  - 10"))    
      {
          // ??????????????   
      }
      
      if(GUI.Button(Rect(590,160,100,20), "Initial speed"))    
      {
          // ??????????????     
      }




}

Hmm.

Create a speed variable, make it an int or a float, your choice, it’s your game, you have a better idea how how it functions.

Create an initVel variable to hold the inital velocity.

for the increase

speed += 10;

for the decrease(make sure you observe negative numbers), maybe an if statement checking for less than zero

speed -= 10;

and for the last

speed = initVel;

Thank you for your help.

Here my code modify with your help

#pragma strict 
public var target_Path1 : GameObject; 
public var time = 300.0;               
public var initVitesse = 300;          




private var tabt : Transform[];
 private var running = false; 
 private var paused = false;
 private var fraction = 0.0; 
 
 function SetPath (pathObject : GameObject){
     var id : int = 0;
     tabt =null;
     tabt = new Transform[pathObject.transform.childCount];
     for(var child: Transform in pathObject.transform)     {
            tabt[id++] = child.transform;
                 }
  WalkThePath();
                                           }
  
 
 
 function WalkThePath() {    
 paused = false;
 running = true;
 fraction = 0.08;  

  while (running) {
         transform.position = iTween.PointOnPath(tabt, fraction);
         
 if (!paused)
          fraction += Time.deltaTime / time;
 if (fraction > 1.0) fraction = 0.0; 
 
        var futurePos = iTween.PointOnPath(tabt, fraction + 0.0001); 
        transform.LookAt(futurePos); 
		
               yield;
                   } 
                      }
                   







     
     // Les boutons de GUI--------------------------                   
function OnGUI(){
    if(GUI.Button(Rect(290,80,100,20), "commencer"))    
    {
           SetPath(target_Path1);    
    }    
   
   
     if(GUI.Button(Rect(390,80,100,20), "Pause"))    
     {  
           paused = true;    
     }     
     
     
     if(GUI.Button(Rect(490,80,100,20), "Reprise"))    
     {
            paused = false;    
     }     
     
     if(GUI.Button(Rect(390,100,120,20), "Reculer par étape")) 
     {       
           fraction -= 0.2 / time; 
           if (fraction < 0.0) fraction = 0.0;   
     }    
     
     
     
     if(GUI.Button(Rect(510,100,120,20), "Avancer par étape")) 
     {       
           fraction += 0.2 / time; 
           if (fraction < 0.0) fraction = 0.0;   
     }    
     
       if(GUI.Button(Rect(590,80,100,20), "Stop"))    
      {
          running = false;    
      }
	  
	  
		  
	  if(GUI.Button(Rect(440,120,100,20), "Ralentir "))    
      {
          time += 10;  
      }
 
      if(GUI.Button(Rect(440,140,100,20), "Accelerer"))    
      {
          time -= 10;  
      }
 
      if(GUI.Button(Rect(440,160,100,20), "vitesse initiale"))    
      {
          time = initVitesse;   
      }
	  
	  
	  
	  
	  
	  
	  
	  
	  
          }