-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTimeRateScript.cs
32 lines (24 loc) · 1006 Bytes
/
TimeRateScript.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//Script that attaches to a slider UI for adjusting the rate at which time flows in a scene.
//Rate of 1 is regular time
// Rate < 1 is slow motion. 0 is paused. Updates do not happen at 0 rate.
public class TimeRateScript : MonoBehaviour {
public Slider timescale_slider;
public InputField timescale_input;
// Use this for initialization
void Start () {
timescale_slider.onValueChanged.AddListener(delegate { UpdateTimeScale(timescale_slider.value); });
timescale_input.onEndEdit.AddListener(delegate { UpdateTimeScale(float.Parse(timescale_input.text)); });
}
private void UpdateTimeScale(float value)
{
//Update the slider and inputfield to ensure the correct value shown
timescale_input.text = value.ToString("F2");
timescale_slider.value = value;
//Update the time scale.
Time.timeScale = value;
}
}