JY-Dev Tech Blog

유니티(Unity) - GlobalComponent(SharedPreference?) 설정방법 본문

유니티

유니티(Unity) - GlobalComponent(SharedPreference?) 설정방법

JY-Dev 2020. 7. 28. 14:46

[OverView]

이번에는 GlobalComponent를 생성하는 방법에 대해 알려드리겠습니다.

 

이건 엄청 간단한데 일단 c# 스크립트를 만들어주도록 합시다.

 

 

그다음에는

Awake() 함수에 DontDestroyOnLoad로 이 스크립트가 파괴되지 않도록 설정해줍니다.

그리고 이 스크립트의 Instance를 지정해주어서 사용하실때 인스턴스를 불러서 사용하면 됩니다.

 

[Awake]

이 함수는 항상 Start 함수의 이전 및 프리팹의 인스턴스화 직후에 호출됩니다. (만약 게임 오브젝트가 시작할 때 무효인 경우, 활성화되거나 연결된 하나의 스크립트 함수가 호출될 때까지, Awake는 호출되지 않습니다.)

 

감사합니다.

 

※ 참고문헌

https://docs.unity3d.com/kr/530/Manual/ExecutionOrder.html

 

유니티 - 매뉴얼: 이벤트 함수의 실행 순서

자동 메모리 관리를 이해하기 이벤트 함수의 실행 순서 Unity 스크립팅시, 미리 정의된 순서대로 실행되는 많은 이벤트 함수가 있습니다. 아래에서는, 실행 순서를 설명합니다. 에디터 __ Reset : __

docs.unity3d.com

https://docs.unity3d.com/kr/530/ScriptReference/Object.DontDestroyOnLoad.html

 

Unity - 스크립팅 API: Object.DontDestroyOnLoad

When loading a new level all objects in the scene are destroyed, then the objects in the new level are loaded. In order to preserve an object during level loading call DontDestroyOnLoad on it. If the object is a component or game object then its entire tra

docs.unity3d.com

 

Comments