커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
4주차 숙제관련! time에 대해서 헷갈리는 게 있습니다.
undefined주차
북마크
이*환
댓글
3
추천
0
조회수
10
조회수
10
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


숙제에서 한 내용대로 30초 시간제한을 두는 건 했는데 그 뒤에 다시 시작 버튼을 누르니 시간이 흐르지 않습니다.

시간 제한이 없을 때는 정상작동 했는데 30초 시간제한을 뒀을 때 문제가 생기는 이유를 알고 싶습니다.

혹시나 해서 MainScene에서 시간제한으로 게임이 끝났을 때 time=0; 으로 바꾸니 정상작동했습니다.

이게 왜 이러는 걸까요...



스파르타 즉문즉답




using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;


public class gameManager : MonoBehaviour
{
    public Text timeTxt;
    float time;
    public GameObject card;
    public static gameManager I;
    public GameObject firstCard;
    public GameObject secondCard;
    public GameObject endTxt;
    private void Awake()
    {
        I = this;
    }
    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;
            newCard.transform.position = new Vector3((i % 4) * 1.4f - 2.1f, (i / 4) * 1.4f - 3.0f, 0);


            string rtanName = "rtan" + rtans[i].ToString();
            newCard.transform.Find("front").GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>(rtanName);
        }
    }


    public void isMatched()
    {
        string fisrtCardImage = firstCard.transform.Find("front").GetComponent<SpriteRenderer>().sprite.name;
        string secondCardImage = secondCard.transform.Find("front").GetComponent<SpriteRenderer>().sprite.name;
        if (fisrtCardImage == secondCardImage)
        {
            firstCard.GetComponent<card>().destroyCard();
            secondCard.GetComponent<card>().destroyCard();
            int cardLeft = GameObject.Find("cards").transform.childCount;
            if (cardLeft == 2)
            {
                endTxt.SetActive(true);
                Time.timeScale = 0.0f;
            }
        }
        else
        {
            firstCard.GetComponent<card>().closeCard();
            secondCard.GetComponent<card>().closeCard();
        }
        firstCard = null;
        secondCard = null;
    }


   


    public void Update()
    {
        time += Time.deltaTime;
        timeTxt.text = time.ToString("N2");
   
        if (time>30)
        {
            Debug.Log(time);
            endTxt.SetActive(true);
            Time.timeScale = 0.0f;
            time = 0;
        }
  
    }
}



<

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.SceneManagement;

public class endTxt : MonoBehaviour

{

  public void Retry()

  {

    SceneManager.LoadScene("MainScene");

    Time.timeScale = 1.0f;

  }

}

/>




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