-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a ui with speed/play/pause/reset controls
- Loading branch information
1 parent
0c6d722
commit 488473c
Showing
2 changed files
with
1,308 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
| ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class UI : MonoBehaviour { | ||
|
||
public Text generateButton; | ||
public Text playButton; | ||
public Text speed; | ||
public Text step; | ||
|
||
private void Update () { | ||
speed.text = State.STEPS_PER_SECOND.ToString(); | ||
step.text = "Step: " + Simulation.CURRENT_STEP.ToString(); | ||
} | ||
|
||
public void FasterButtonClicked () { | ||
State.STEPS_PER_SECOND = Mathf.Clamp(++State.STEPS_PER_SECOND, 1, 30); | ||
} | ||
|
||
public void GenerateButtonClicked () { | ||
generateButton.text = "Generate"; | ||
playButton.text = "Play"; | ||
State.PAUSED = true; | ||
Simulation.Init(); | ||
Simulation.Render(); | ||
} | ||
|
||
public void PlayButtonClicked () { | ||
generateButton.text = "Reset"; | ||
if ( State.PAUSED ) { | ||
State.PAUSED = false; | ||
playButton.text = "Pause"; | ||
State.DELTA_TIME = 0; | ||
Simulation.Step(); | ||
Simulation.Render(); | ||
} else { | ||
State.PAUSED = true; | ||
playButton.text = "Play"; | ||
} | ||
} | ||
|
||
public void SlowerButtonClicked () { | ||
State.STEPS_PER_SECOND = Mathf.Clamp(--State.STEPS_PER_SECOND, 1, 30); | ||
} | ||
|
||
} |
Oops, something went wrong.