PlayerPrefs를 활용한 스코어 저장
PlayerPrefs
https://docs.unity3d.com/kr/530/ScriptReference/PlayerPrefs.html
PlayerPrefs은 <Key Value>로 데이터를 저장하는 클래스이다.
int, float, string 타입의 데이터를 저장한다. Key값은 string이며, Key는 Value를 찾기 위한 식별자이다.
PlayerPrefs은 데이터를 메모리 상에 저장하여, 이를 하드 드라이브에 저장한다. 메모리 상의 저장은 임시적인 저장이므로, 저장이 이루어지지 않을 수 있다.
DeleteAll() : 모든 데이터를 삭제한다. 이 함수를 사용할 경우 경고 메시지가 출력
DeleteKey(String Key) : Key와 대응하는 값을 삭제
HasKey(String Key) : Key가 존재하는지 확인
Save() : 수정된 모든 preferences를 파일에 저장( 메모리 상에 저장된 데이터를 하드 드라이브에 저장)
SetInt(string Key, int value) : Key 값으로 int 형 데이터를 저장
SetFloat(string Key, float value) : Key 값으로 float 형 데이터를 저장
SetString(string Key, string value) : Key 값으로 string 형 데이터를 저장
GetInt(string Key) : Key 값으로 저장된 int 형 데이터를 불러옴
GetFloat(string Key) : Key 값으로 저장된 float 형 데이터를 불러옴
GetString(string Key) : Key 값으로 저장된 string 형 데이터를 불러옴
PlayerPrefs.SetInt로 점수를 저장해 보았다.
-이전 플레이의 점수가 저장되어 시작하자 마자 100점이 뜬다
'유니티 심화' 카테고리의 다른 글
라이트 매핑(Light Mapping) (1) | 2023.08.30 |
---|---|
Raycast-총알 발사 로직 수정/ 동적 장애물-NavMeshobstacle (0) | 2023.08.29 |
Object Pooling 연습 - 총알 생성 (0) | 2023.08.28 |
Object Pooling으로 몬스터 생성 (0) | 2023.08.28 |
Unity UI-버튼-애니메이션, Play씬에서 HpBar 생성 (0) | 2023.08.25 |