- Home /
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("\n"[0]);
for(i = counter; i < lines.Length; i++)
{
DrehungSpeed_alt = DrehungSpeed;
DrehungRpm_alt = DrehungRpm;
DrehungHitze_alt = DrehungHitze;
var values = lines[i].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[i].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 + "\n" + "Geschwindigkeit : " + DigitalSpeed + "\n" + "Umdrehungen Pro Minute : " + DigitalRPM + "\n");
The German variable names I can manage, but your formatting makes it unreadable regardless. Please fix.
It does to people who you want to read that mess. We aren't compilers.
short from of the code : i'm reading a file with racing values like velocity and engine rotation and rotating a dashboard's needles with them. now i want play, pause and rewind buttons.
Answer by Waz · Jul 12, 2011 at 01:42 PM
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.
I think you need to restructure that code to have a single loop. For example, how are you going to pause or play while rewinding?
So learn, and stop contradicting. "Formatting doesn't matter at all" is about the most ignorant comment I've ever seen on this site.
Your answer
![](https://koobas.hobune.stream/wayback/20220612141631im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to play sound on GUI touch IOS 1 Answer
A node in a childnode? 1 Answer
Unity android button and Time.timescale problems 1 Answer
How to Disable/Inactive NGUI Button on Game Pause? 0 Answers
Help with GUI clicking ??? 1 Answer