
안녕하세요~ 1주차 10번째 강의, 게임 끝내기 편을 학습하다 오류가 생겨 질문을 남깁니다.
강의대로 모든 절차를 밟고, on click에도 Panel 을 드래그 앤 드롭으로 연동해두었으나 Main Scene이 제대로 초기화되지 않네요.
혹시 코드 내 Main Scene의 띄어쓰기가 문제일까 싶어, MainScene과 Main Scene 양쪽 모두 실험해보았지만 그대로였습니다.
.png)
.png)
.png)
작성한 코드 및 에러 메세지
게임 매니저의 코드입니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public GameObject Rain;
public static GameManager I;
public Text scoreText;
public Text timeText;
public GameObject panel;
int totalScore;
float limit = 10f;
void Awake()
{
I = this;
}
// Start is called before the first frame update
void Start()
{
InvokeRepeating("makeRain", 0, 0.5f);
}
// Update is called once per frame
void Update()
{
limit -= Time.deltaTime;
if (limit < 0)
{
Time.timeScale = 0.0f;
panel.SetActive(true);
limit = 0.0f;
}
timeText.text = limit.ToString("N2");
}
void makeRain()
{
Instantiate(Rain);
}
public void addScore(int score)
{
totalScore += score;
scoreText.text = totalScore.ToString();
}
public void retry()
{
SceneManager.LoadScene("Main Scene");
}
}
패널(버튼)의 코드입니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class panel : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void retry()
{
GameManager.I.retry();
}
}
