103 lines
2.4 KiB
C#
103 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class PauseMenu : MonoBehaviour
|
|
{
|
|
bool paused = false;
|
|
public GameObject PauseMenuUI;
|
|
public GameController gameController;
|
|
public Slider horizontalMoveSlider;
|
|
public Slider verticalMoveSlider;
|
|
public GerakanRaket gerakanRaket;
|
|
|
|
void Start()
|
|
{
|
|
LoadSettings();
|
|
}
|
|
|
|
void LoadSettings()
|
|
{
|
|
|
|
float horizontalSpeed = PlayerPrefs.GetFloat("HorizontalSpeed", 1f);
|
|
horizontalMoveSlider.value = horizontalSpeed;
|
|
gerakanRaket.horizontalSpeed = horizontalSpeed;
|
|
|
|
|
|
float verticalSpeed = PlayerPrefs.GetFloat("VerticalSpeed", 1f);
|
|
verticalMoveSlider.value = verticalSpeed;
|
|
gerakanRaket.verticalSpeed = verticalSpeed;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
{
|
|
pauseGame();
|
|
}
|
|
}
|
|
|
|
public void pauseGame()
|
|
{
|
|
if (paused)
|
|
{
|
|
Time.timeScale = 1;
|
|
paused = false;
|
|
PauseMenuUI.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
Time.timeScale = 0;
|
|
paused = true;
|
|
PauseMenuUI.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void RestartGame()
|
|
{
|
|
if (gameController != null)
|
|
{
|
|
gameController.ResetScores();
|
|
}
|
|
|
|
ResetMainScene();
|
|
Time.timeScale = 1;
|
|
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
|
}
|
|
|
|
public void QuitGame()
|
|
{
|
|
if (gameController != null)
|
|
{
|
|
gameController.ResetScores();
|
|
}
|
|
|
|
ResetMainScene();
|
|
Time.timeScale = 1;
|
|
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
|
|
}
|
|
|
|
private void ResetMainScene()
|
|
{
|
|
GameObject player = GameObject.FindWithTag("Player");
|
|
if (player != null)
|
|
{
|
|
player.transform.position = Vector3.zero;
|
|
}
|
|
}
|
|
|
|
public void UpdateHorizontalMove(float value)
|
|
{
|
|
gerakanRaket.horizontalSpeed = value;
|
|
PlayerPrefs.SetFloat("HorizontalSpeed", value);
|
|
}
|
|
|
|
public void UpdateVerticalMove(float value)
|
|
{
|
|
gerakanRaket.verticalSpeed = value;
|
|
PlayerPrefs.SetFloat("VerticalSpeed", value);
|
|
}
|
|
}
|