2
PlayerPerfabs를 사용하여 플레이어가 잠금을 해제하고 게임 중에 포인트가있는 플레이어 데이터를 저장하고 있으며, 재생 중 PlayerPerfabs 데이터를 정기적으로 (예 : 5 초마다) 업데이트하고 싶습니다. 나는 수준의 정보 등을 얻을 포인트 플레이어와 같은 글로벌 데이터를 보유 할 ApplicationModel라는 클래스 ..유니티가 PlayerPrefs 데이터를 정기적으로 설정합니다.
public ApplicationModel: MonoBehaviour{
public static int point {get;set;}
//try to load the PlayerPerfabs when start game.
static ApplicationModel(){
if(PlayerPerfabs.HasKey("point")){
point = PlayerPerfabs.GetInt("point");
}else{
point = 0;
}
}
//coroutine to set the data to PlayerPerfabs
IEnumerator Save()
{
while (true)
{
Debug.Log("setting playerperfab ....");
yield return new WaitForSeconds(5f);
ApplicationModel.RestorePerfab();
}
}
public static void RestorePerfab(){
PlayerPerfabs.SetInt("point", point);
}
private void Start(){
StartCoroutine(Save());
}
}
했다 그러나 코 루틴은 콘솔 로그 (로그가 인쇄되지 않았다 원인)에 따라 실행되지 않았다.
게임 객체에이 스크립트를 첨부하지 않았지만이 객체를 게임 객체에 첨부하면 장면이 변경되거나 gameobject가 파괴되면 정기적으로 저장이 종료됩니다. 그러면 어떻게 할 수 있을까요?
나는 싱글 톤을 사용하는 것이 더 좋을 것이라고 생각한다. 데이터 링크가 복제 될 필요가 없기 때문에. – Andromelus