유니티 심화

절대강좌 유니티 - TMP_Text, 점수표시, PlayerPrefs, 오브젝트풀링

다모아 2023. 8. 29. 10:47

GameManager
GameManager
MonsterController

 

GameManager - 오브젝트 풀링

 

PlayerPrefs 경로

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestPlayerPrefsMain : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        //PlayerPrefs.SetInt("player_lv", 1);
        bool hasKey = PlayerPrefs.HasKey("player_damage");
        Debug.LogFormat("hasKey: {0}", hasKey);

        float damage0 = PlayerPrefs.GetFloat("player_damage");
        Debug.LogFormat("damage0: {0}", damage0);

        //키가 없다면 기본값을 설정해서 얻고싶다
        float damage1 = PlayerPrefs.GetFloat("player_damage", 1.5f);
        Debug.LogFormat("damage1: {0}", damage1);

        //int lv = PlayerPrefs.GetInt("player_lv");
        //Debug.LogFormat("lv: {0}", lv);
        
        PlayerPrefs.DeleteKey("player_lv");
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

 

PlayerPrefs는 보안성이 좋지않다. [아무나 수정가능]