
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
1. 강의에서 마지막 카드 두 장을 뒤집었을 때 끝이 뜨고 그 두장은 사라질 수 있게 GameEnd를 선언하는데,
취향차이로 선생님은 Invoke("GameEnd",1f); 앞에 //를 붙이셨습니다.
저는 사라지게 만들고 싶어서 //를 붙이지 않았는데도 끝이 나온후에 마지막 두 장이 사라지지 않네요.
2. gameManger.cs의 isMatched 함수안에 이미
Time.timeScale=0f;
endTxt.SetActive(true)
가 들어있는데
GameEnd에 굳이 같은 내용이 들어가야하는 이유를 모르겠습니다!
답변부탁드립니다. 감사합니다!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class gameManager : MonoBehaviour
{
public Text timeTxt;
public GameObject endTxt;
public GameObject card;
float time;
public static gameManager I;
void Awake()
{
I = this;
}
public GameObject firstCard;
public GameObject secondCard;
// Start is called before the first frame update
void Start()
{
int[] rtans = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7 };
rtans = rtans.OrderBy(item => Random.Range(-1.0f, 1.0f)).ToArray();
for (int i = 0; i < 16; i++)
{
GameObject newCard = Instantiate (card);
newCard.transform.parent = GameObject.Find("cards").transform;
float x = (i / 4) * 1.4f - 2.1f;
float y = (i % 4) * 1.4f - 3.0f;
newCard.transform.position = new Vector3(x,y,0);
string rtanName = "rtan" + rtans[i].ToString();
newCard.transform.Find("front").GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>(rtanName);
}
Time.timeScale = 1.0f;
}
// Update is called once per frame
void Update()
{
time += Time.deltaTime;
timeTxt.text = time.ToString("N2");
}
public void isMatched()
{
string firstCardImage = firstCard.transform.Find("front").GetComponent<SpriteRenderer>().sprite.name;
string secondCardImage = secondCard.transform.Find("front").GetComponent<SpriteRenderer>().sprite.name;
if (firstCardImage == secondCardImage)
{
firstCard.GetComponent<card>().destroyCard();
secondCard.GetComponent<card>().destroyCard();
int cardsLeft = GameObject.Find("cards").transform.childCount;
if(cardsLeft == 2)
{
Time.timeScale = 0f;
endTxt.SetActive(true);
Invoke("GameEnd",1f);
}
}
else
{
firstCard.GetComponent<card>().closeCard();
secondCard.GetComponent<card>().closeCard();
}
firstCard = null;
secondCard = null;
}
void GameEnd()
{
Time.timeScale = 0f;
endTxt.SetActive(true);
}
}
