Pause, Play and Rewind buttons for a function

Hello,

I have written a function and in my Project’s GUI i got buttons with the names :

Pause, Play, Rewind.

It’s all good until now, but when i capsule the buttons into each other (first play gets pressed, then rewind, pause, play etc)

It starts my function Multiple times and this isn’t what i’m looking for.

Linking the functions OnGUI() and Dashboard()

 function Dashboard()
{
    var lines = Source.text.Split("

"[0]);
for(i = counter; i < lines.Length; i++)
{

        DrehungSpeed_alt = DrehungSpeed;
        DrehungRpm_alt = DrehungRpm;
        DrehungHitze_alt = DrehungHitze;
        var values = lines*.Split(";"[0]);*

DrehungSpeed = int.Parse(values[4]);
DrehungRpm = int.Parse(values[8]);
DigitalSpeed = int.Parse(values[4]);
zeilennr = i;
//DrehungHitze = int.Parse(values[XXXX]);
DrehungSpeed = Mathf.Clamp(DrehungSpeed/300.0 * 180.0,0.0,180.0);
DrehungRpm = Mathf.Clamp(DrehungRpm/8000.0 * 240.0,0.0,240.0);

DigitalRPM = int.Parse(values[8]);

  •  yield WaitForSeconds(0.5);*
    
  •  counter = i;*
    
  •  if(Paused == true)* 
    
  •  {* 
    
  •  	Rewinding = false;*
    
  •  	ErsterWert = false;*
    
  •  	LetzterWert = false;*
    
  •  	break;*
    
  •  }*
    
  •  if(Rewinding == true)*
    
  •  {*
    
  •  	    Paused = false;*
    
  •  	    ErsterWert = false;*
    
  •  	    LetzterWert = false;*
    
  •  	    for(i = counter; i > 4; i--)*
    
  •  {*
    

values = lines*.Split(“;”[0]);*
DrehungSpeed_alt = DrehungSpeed;
DrehungRpm_alt = DrehungRpm;
DrehungHitze_alt = DrehungHitze;

DrehungSpeed = int.Parse(values[4]);
DrehungRpm = int.Parse(values[8]);
DigitalSpeed = int.Parse(values[4]);

//DrehungHitze = int.Parse(values[XXXX]);
DrehungSpeed = Mathf.Clamp(DrehungSpeed/300.0 * 180.0,0.0,180.0);
DrehungRpm = Mathf.Clamp(DrehungRpm/8000.0 * 240.0,0.0,240.0);

DigitalRPM = int.Parse(values[8]);
* yield WaitForSeconds(0.5);*
* counter = i;*

* }*

}

* if(ErsterWert == true)*
* {*
* Paused = false;*
* Rewinding = false;*
* LetzterWert = false;*

* values = lines[4].Split(“;”[0]);*
* DrehungSpeed = int.Parse(values[4]);*
* DrehungRpm = int.Parse(values[8]);*
* DigitalSpeed = int.Parse(values[4]);*
* //DrehungHitze = int.Parse(values[XXXX]);*

_ DrehungSpeed = Mathf.Clamp(DrehungSpeed/300.0 * 180.0,0.0,180.0);
DrehungRpm = Mathf.Clamp(DrehungRpm/8000.0 * 240.0,0.0,240.0);_

* DigitalRPM = int.Parse(values[8]);*
* yield WaitForSeconds(0.5);*
* }*

* if(LetzterWert == true)*
* {*
* Paused = false;*
* Rewinding = false;*
* ErsterWert = false;*

* var endwert = lines.length - 1.0;*

* values = lines[endwert].Split(“;”[0]);*
* DrehungSpeed = int.Parse(values[4]);*
* DrehungRpm = int.Parse(values[8]);*
* DigitalSpeed = int.Parse(values[4]);*
* //DrehungHitze = int.Parse(values[XXXX]);*

_ DrehungSpeed = Mathf.Clamp(DrehungSpeed/300.0 * 180.0,0.0,180.0);
DrehungRpm = Mathf.Clamp(DrehungRpm/8000.0 * 240.0,0.0,240.0);_

* DigitalRPM = int.Parse(values[8]);*
* yield WaitForSeconds(0.5);*

* }*

}
}function OnGUI(){

* if(GUI.Button(Rect(10,10,50,50),“Play”))*

* { *
* Dashboard(); *
* }*

* if(GUI.Button(Rect(10,130,70,50),“Rewind”))*
* {*
* Rewinding = true;*
* }*

* if(GUI.Button(Rect(10,190,100,50),“Erster Wert”))*
* {*
* ErsterWert = true;*
* }*

* if(GUI.Button(Rect(10,250,100,50),“Letzter Wert”))*
* {*
* LetzterWert = true;*
* }*

* if(GUI.Button(Rect(10,310,100,50),“Close”))*
* {*
* Application.Quit();*
* }*

* GUI.Box(Rect(0,1080,Screen.width,Screen.height/4.0),"Zeilennummer : " + i + "
" + "Geschwindigkeit : " + DigitalSpeed + "
" + "Umdrehungen Pro Minute : " + DigitalRPM + "
");*

It’s starting Dashboard multiple times, because that’s what your code tells it to do (eg. whenever you toggle Pause). Start it once, then control it through the variables, otherwise you’re just going to get into a big mess.