
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
게임매니저에서 뭔갈 잘못한것같은데 뭐가 잘못됐는지 모르겠어요
작성한 코드 및 에러 메세지
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Object.Instantiate[T] (T original) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnityEngineObject.bindings.cs:285)
gameManager.makeSquare () (at Assets/Scripts/gameManager.cs:74)
gameManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class gameManager : MonoBehaviour
{
public GameObject square;
public Text timeTxt;
float alive = 0f;
public static gameManager I;
public GameObject endPanel;
public Text thisScoreTxt;
bool isRunning = true;
public Animator anim;
public Text maxScoreTxt;
public void retry()
{
SceneManager.LoadScene("MainSecene");
}
public void gameOver()
{
isRunning = false;
Invoke("timeStop", 0.5f);
anim.SetBool("isDie", true);
endPanel.SetActive(true);
thisScoreTxt.text = alive.ToString("N2");
if(PlayerPrefs.HasKey("bastscore") == false)
{
PlayerPrefs.SetFloat("bastscore", alive);
}
else
{
if(alive > PlayerPrefs.GetFloat("bastscore"))
{
PlayerPrefs.SetFloat("bastscore", alive);
}
}
float maxScore = PlayerPrefs.GetFloat("bastscore");
maxScoreTxt.text = maxScore.ToString("N2");
}
private void Awake()
{
I = this;
}
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
InvokeRepeating("makeSquare", 0.0f, 0.5f);
}
// Update is called once per frame
void Update()
{
if (isRunning)
{
alive += Time.deltaTime;
timeTxt.text = alive.ToString("N2");
}
}
void makeSquare()
{
Instantiate(square);
}
void timeStop()
{
Time.timeScale = 0f;
}
}
//PlayerPrefs.SetInt('age', 10);
//PlayerPrefs.SetString('name', 'donghyn lee');
//PlayerPrefs.GetString('name');
square.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class w1uq43 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
float x = Random.Range(-3f, 3f);
float y = Random.Range(3f, 5f);
transform.position = new Vector3(x, y, 0);
float size = Random.Range(0.5f, 1.5f);
transform.localScale = new Vector3(size, size, 1);
}
// Update is called once per frame
void Update()
{
if (transform.position.y < -5.0f)
{
Destroy(gameObject);
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "balloon")
{
gameManager.I.gameOver();
}
}
}
shield.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shield : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(mousePos.x, mousePos.y, 0);
}
}
오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.
Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.
Tip 2) Ctrl+A(맥의 경우 Command+A) 단축키로 코드를 한 번에 선택할 수 있어요!
