유니티

[유니티]데이터 저장 및 불러오기 PlayerPrefs

유니티 게임 개발 2024. 12. 23. 18:11

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement; // <- 꼭 추가

public class ZZZPractice : MonoBehaviour
{
    float score = 1.23f;

    void Start()
    {
        PlayerPrefs.SetFloat("BestScore", score); // "BestScore"라는 값에 score 데이터를 저장
        PlayerPrefs.GetFloat("BestScore"); // "BestScore"라는 값에 저장된 데이터를 불러옴
    }
}

 

PlayerPrefs.SetFloat("BestScore", score);

= "BestScore"라는 값에 score라는 실수형 데이터를 넣어

 

PlayerPrefs.GetFloat("BestScore");

= "BestScore"라는 값에 score라는 실수형 데이터를 가져와