Witam ponownie. Ostatnio napisałem skrypt, żeby wyświetlić takie testowe menu podczas rozgrywki. I podczas wyświetlania tego menu, chciałem, aby czas przestał płynąć. Podam poniżej kod, który odpowiada za to. Z góry dzięki za pomoc.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InGameMenu : MonoBehaviour
{
private bool gamePaused = false;
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (gamePaused)
{
Time.timeScale = 1;
gamePaused = false;
}
else
{
Time.timeScale = 0;
gamePaused = true;
}
}
}
void OnGUI()
{
if (gamePaused)
{
Color background = Color.black;
background.a = 0.3f;
DrawQuad(new Rect(0, 0, Screen.width, Screen.height), background);
if (GUI.Button(new Rect(Screen.width / 2 - 50, 20, 100, 20), "Play"))
{
}
if (GUI.Button(new Rect(Screen.width / 2 - 50, 50, 100, 20), "Score"))
{
}
if (GUI.Button(new Rect(Screen.width / 2 - 50, 80, 100, 20), "Quit"))
{
}
}
}
void DrawQuad(Rect position, Color color)
{
Texture2D texture = new Texture2D(1, 1);
texture.SetPixel(0, 0, color);
texture.Apply();
GUI.skin.box.normal.background = texture;
GUI.Box(position, GUIContent.none);
}
}