
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
캐릭터 카드를 천천히 누르는 경우 모두 눌렀을 때 게임이 잘 종료가 되는데 빠르게 누르는 경우에 종료가 안됩니다..
임의로 종료 시간을 40초로 변경하고 진행 중인데 빠르게 누르면 처리가 누락되는지 제한 시간까지 계속 시간이 흐릅니다..
대략의 시나리오는 어려울 것 없이 마지막 4장이 남은 상황에서 엄청 빨리 눌러 게임을 종료시키면 재현됩니다ㅠ
화면 녹화를 해놨는데 용량이 커서 안올라가네요..
무엇을 놓쳤을까요?


public class GameManager : MonoBehaviour
{
public static GameManager I;
public Text timeTxt;
public GameObject card;
public GameObject firstCard;
public GameObject secondCard;
public GameObject endTxt;
private float time;
void Awake()
{
I = this;
}
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
int[] shuffledRtanCards = ShuffleRtanCards();
for (int i = 0; i < 16; i++)
{
GenerateRtanCard(i, GenerateRtanCardName(shuffledRtanCards[i]));
}
}
private int[] ShuffleRtanCards()
{
return new int[] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7 }
.OrderBy(element => Random.Range(-1.0f, 1.0f))
.ToArray();
}
private string GenerateRtanCardName(int rtanNumber)
{
return "rtan" + rtanNumber.ToString();
}
private GameObject GenerateRtanCard(int index, string rtanName)
{
GameObject newRtanCard = Instantiate(card);
Transform newRtanTransform = newRtanCard.transform;
float positionX = (index / 4) * 1.4f - 2.1f;
float positionY = (index % 4) * 1.4f - 3.0f;
newRtanTransform.position = new Vector3(positionX, positionY, 0);
newRtanTransform.Find("Front").GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>(rtanName);
newRtanTransform.parent = GameObject.Find("Cards").transform;
return newRtanCard;
}
// Update is called once per frame
void Update()
{
time += Time.deltaTime;
timeTxt.text = time.ToString("N2");
if (time > 40.0f)
{
endTxt.SetActive(true);
Time.timeScale = 0.0f;
}
}
public void IsMatched()
{
string firstCardImageName = FindCardImageName(firstCard);
string secondCardImageName = FindCardImageName(secondCard);
Card firstCardComponent = firstCard.GetComponent<Card>();
Card secondCardComponent = secondCard.GetComponent<Card>();
if (firstCardImageName == secondCardImageName)
{
firstCardComponent.DestroyCard();
secondCardComponent.DestroyCard();
int cardsLeft = GameObject.Find("Cards").transform.childCount;
if (cardsLeft == 2)
{
Invoke(nameof(GameEnd), 1f);
}
}
else
{
firstCardComponent.CloseCard();
secondCardComponent.CloseCard();
}
firstCard = null;
secondCard = null;
}
private string FindCardImageName(GameObject givenCard)
{
return givenCard.transform
.Find("Front")
.GetComponent<SpriteRenderer>()
.sprite
.name;
}
private void GameEnd()
{
Time.timeScale = 0f;
endTxt.SetActive(true);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Card : MonoBehaviour
{
public Animator animator;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OpenCard()
{
animator.SetBool("isOpen", true);
transform.Find("Front").gameObject.SetActive(true);
transform.Find("Back").gameObject.SetActive(false);
if (GameManager.I.firstCard == null)
{
GameManager.I.firstCard = gameObject;
}
else
{
GameManager.I.secondCard = gameObject;
GameManager.I.IsMatched();
}
}
public void DestroyCard()
{
Invoke(nameof(DestroyCardInvoke), 1.0f);
}
void DestroyCardInvoke()
{
//Destroy(gameObject);
DestroyImmediate(gameObject);
}
public void CloseCard()
{
Invoke(nameof(CloseCardInvoke), 1.0f);
}
void CloseCardInvoke()
{
animator.SetBool("isOpen", false);
transform.Find("Back").gameObject.SetActive(true);
transform.Find("Front").gameObject.SetActive(false);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class EndTxt : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void ReStart()
{
SceneManager.LoadScene("MainScene");
}
}
