-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlay_Pause.cs
49 lines (44 loc) · 1.05 KB
/
Play_Pause.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Play_Pause : MonoBehaviour
{
public Sprite[] sprites;
public Button home;
public Button play_pause;
private bool isPaused;
private Image myImage;
// Use this for initialization
void Start()
{
isPaused = false;
myImage = play_pause.GetComponent<Image>();
myImage.sprite = sprites[0];
home.gameObject.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
PlayAndPause();
}
}
public void PlayAndPause()
{
isPaused = !isPaused;
if (isPaused)
{
home.gameObject.SetActive(true);
myImage.sprite = sprites[1];
Time.timeScale = 0.0f;
}
else
{
home.gameObject.SetActive(false);
myImage.sprite = sprites[0];
Time.timeScale = 1f;
}
}
}