커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
4-7
undefined주차
북마크
이*비
댓글
5
추천
0
조회수
31
조회수
31
답변 완료

강의 보면서 따라하는데 저는 카드를 다 뒤집었는데도 endtxt가 안 뜹니다.

뭐가 잘못 된 걸까요? ㅠ

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
using Unity.VisualScripting.Antlr3.Runtime.Misc;


public class gameManager : MonoBehaviour
{
    public Text timeTxt;
    public GameObject card;
    float time;
    public static gameManager I;
    public GameObject Endtxt;
    public GameObject firstcard;
    public GameObject secondcard;

    // Start is called before the first frame update

    void Awake()
    {
        I = this;
    }

    void Start()
    {
        Time.timeScale = 1.0f;

        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);
           }
    }


    // 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);
            }

        }
        else
        {   
            firstcard.GetComponent<card>().closeCard();
            secondcard.GetComponent<card>().closeCard();
        }

        firstcard =  null;
        secondcard = null;
    }
}


취소
 공유
취소
댓글 0
댓글 알림
나의얼굴