Skip to content

Instantly share code, notes, and snippets.

@gkagm2
Created April 20, 2019 14:38
Show Gist options
  • Save gkagm2/f28b6b8ab00f122f723495d1fede93f0 to your computer and use it in GitHub Desktop.
Save gkagm2/f28b6b8ab00f122f723495d1fede93f0 to your computer and use it in GitHub Desktop.
PlayerPrefs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor; // need
public class csGameManager : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
private void OnGUI()
{
if(GUI.Button(new Rect(30, 50, 180,30), " Set Value"))
{
SetData();
}
if (GUI.Button(new Rect(30, 100, 180, 30), "Get Value"))
{
GetData();
}
}
void SetData()
{
// Key / Value
PlayerPrefs.SetInt("Score", 100);
PlayerPrefs.SetString("Name", "홍길동");
}
void GetData()
{
//Get Value by Key.
int myScore = PlayerPrefs.GetInt("Score");
string myName = PlayerPrefs.GetString("Name", "N/A");
if (EditorUtility.DisplayDialog("알림", "출력할 내용을 선택하세요.", "이름", "점수"))
{
Debug.Log("Name: " + myName);
}
else
{
Debug.Log("Score: " + myScore);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment