
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
c# 스크립트에서 Destory 작성하기 전까지는 강의와 동일하게 잘 작동했습니다
Destory 를 스크립트에 반영하니 동일하지 않은 카드임에도 없어지더라구요ㅠ
제가 오류를 못 찾은건지 unity 에서 어떤 걸 설정하지 않은 건지 모르겠습니다
도움부탁드려요


작성한 코드 및 에러 메세지
카드 스크립트
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Card : MonoBehaviour
{
public int idx = 0;
public GameObject front;
public GameObject back;
public Animator anim;
public SpriteRenderer frontImage;
public void Setting(int number)
{
int idx = number;
frontImage.sprite = Resources.Load<Sprite>($"rtan{idx}");
// $표시를 붙이면 {}안에 자료형을 입력할 수 있음
}
public void OpenCard()
{
if (GameManager.Instance.secondCard != null) return;
anim.SetBool("isOpen", true);
front.SetActive(true);
back.SetActive(false);
// firstCard가 비었다면,
if (GameManager.Instance.firstCard == null)
{
// firstCard에 내 정보를 넘겨준다.
GameManager.Instance.firstCard = this;
}
// firstCard가 비어있지 않다면,
else
{
// secondCard에 내 정보를 넘겨준다.
GameManager.Instance.secondCard = this;
// Matched 함수를 호출해준다.
GameManager.Instance.Matched();
}
}
public void DestoryCard()
{
Invoke("DestroyCardInvoke", 1.0f);
}
void DestroyCardInvoke()
{
Destroy(gameObject);
}
public void CloseCard()
{
Invoke("CloseCardInvoke", 1.0f);
}
void CloseCardInvoke()
{
anim.SetBool("isOpen", false);
front.SetActive(false);
back.SetActive(true);
}
}
게임매니저 스크립트
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public Card firstCard;
public Card secondCard;
public Text timeTxt;
public GameObject endTxt;
public int cardCount = 0;
float time = 0.0f;
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
}
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1.0f;
}
// Update is called once per frame
void Update()
{
time += Time.deltaTime;
timeTxt.text = time.ToString("N2");
}
public void Matched()
{
if (firstCard.idx == secondCard.idx)
{
// 파괴해라.
firstCard.DestoryCard();
secondCard.DestoryCard();
cardCount -= 2;
if (cardCount == 0)
{
endTxt.SetActive(true);
Time.timeScale = 0.0f;
}
}
else
{
// 닫아라.
firstCard.CloseCard();
secondCard.CloseCard();
}
firstCard = null;
secondCard = null;
