Version: 5.3 (switch to 5.4b)
언어English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

MonoBehaviour.OnApplicationFocus(bool)

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

닫기

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

닫기

취소

Switch to Manual

Description

응용프로그램이 포커스 되거나 포커스를 잃었을때 모든 게임오브젝트들에게 보냅니다.

OnApplicationFocus는 함수에서 yield statement를 사용함으로써 간단히 코루틴이 될수 있습니다. 만약 코루틴으로 구현될 경우, 최초 프레임동안 두번 평가될 것입니다: 첫번째는 조기 통보, 두번째는 일반 코루틴 업데이트 스텝에서.

On Android, when the on-screen keyboard is enabled, it will cause OnApplicationFocus( false ) event. Also, if you press "home" at the moment the keyboard is enabled, the OnApplicationFocus() event won't get called, but OnApplicationPause() will be called instead.


        
using UnityEngine;

public class AppPaused : MonoBehaviour { bool isPaused = false;

void OnGUI( ) { if( isPaused ) GUI.Label( new Rect( 100, 100, 50, 30 ), "Game paused" ); }

void OnApplicationFocus( bool focusStatus ) { isPaused = focusStatus; }

void OnApplicationPause( bool pauseStatus ) { isPaused = pauseStatus; } }