Unity/Asset 분석
게임 일시정지하기
lipnus
2021. 6. 11. 14:23
반응형
Time.timescale을 이용하여 정지하는 방법
Time.timescale?
시간이 경과하는 크기를 나타냅니다. 슬로우 모션 효과에 사용될 수 있습니다.
/timeScale/이 1.0인 경우에, 실제 시간과 같은 속도로 경과합니다. /timeScale/이 0.5인 경우에, 실제 시간과 비교해서 2배 느리게 경과합니다.
/timeScale/이 0으로 설정되는 경우에, 일반적으로 프레임비율(framerate)과 독립적으로, 모든 기능을 일시정지 합니다.
public void TogglePauseMenu ()
{
if (GameManager.GameState == GameState.running)
GameManager.SetGameState(GameState.pause);
else if (GameManager.GameState == GameState.pause)
GameManager.SetGameState(GameState.running);
}
public static void SetGameState (GameState newState)
{
GameState = newState; //update the state
if (MultiplayerGame == false) //only in single player games
{
//if the new state is set to running:
if (GameState == GameState.running)
Time.timeScale = 1.0f; //set the time scale to 1.0 to allow the game to run
else if (GameState == GameState.pause) //if the game is paused
Time.timeScale = 0.0f; //to freeze the game
}
CustomEvents.OnGameStateUpdated(); //and trigger the custom event
}
https://docs.unity3d.com/kr/530/ScriptReference/Time-timeScale.html
Unity - 스크립팅 API: Time.timeScale
/timeScale/이 1.0인 경우에, 실제 시간과 같은 속도로 경과합니다. /timeScale/이 0.5인 경우에, 실제 시간과 비교해서 2배 느리게 경과합니다. /timeScale/이 0으로 설정되는 경우에, 일반적으로 프레임비
docs.unity3d.com
반응형