
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
최고 점수 기록을 위해 강의와 교재 내용 대로 PlayerPrefs 를 추가하고 실행하면
아래와 같은 에러가 발생합니다.
해결 방법이 어떻게 되나요?
Assets\Scripts\gameManager.cs(58,13): error CS0103: The name 'playerPrefs' does not exist in the current context
작성한 코드 및 에러 메세지
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class gameManager : MonoBehaviour
{
public static gameManager I;
public GameObject square;
public GameObject endPanel;
public Text timeTxt;
public Text thisScoreTxt;
public Text maxScoreTxt;
float alive = 0f;
bool isRunning = true;
void Awake()
{
I = this;
}
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1.0f;
InvokeRepeating("makeSquare", 0.0f, 0.5f);
}
// Update is called once per frame
void Update()
{
if(isRunning)
{
alive += Time.deltaTime;
timeTxt.text = alive.ToString("N2"); // 소수점 2째 자리까지
}
}
void makeSquare()
{
Instantiate(square);
}
public void gameOver()
{
isRunning = false;
Time.timeScale = 0f;
thisScoreTxt.text = alive.ToString("N2");
endPanel.SetActive(true);
if (PlayerPrefs.HasKey("bestScore") == false)
{
playerPrefs.SetFloat("bestScore", alive);
}
else
{
if (PlayerPrefs.GetFloat("bestScore") < alive)
{
PlayerPrefs.SetFloat("bestScore", alive);
}
}
float maxScore = PlayerPrefs.GetFloat("bestScore");
maxScoreTxt.text = maxScore.ToString("N2");
}
public void retry()
{
SceneManager.LoadScene("MainScene");
}
}
축키로 코드를 한 번에 선택할 수 있어요!
