커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
게임이 멈추면 르탄이도 멈추게 하고싶습니다
게임 개발이 처음이어도 쉽게 배우는 모바일 게임 개발
1주차
북마크
송*민
댓글
14
추천
0
조회수
67
조회수
67
답변 완료

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

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


1주차를 모두 수강한 후, 게임이 멈췄을 때 르탄이는 그대로 움직이는게 의아했습니다.

비는 내리던게 멈추던데 , 르탄이는 왜 안멈출까요?

그래서 르탄이도 멈추는 코드 작성을 시도해보았는데, 제 코드론 게임이 시작하자마자 빗방울 하나만 떨어지고 시간이 흘러가지 않을 뿐이었습니다..


그래서 저는

1) 왜 르탄이만 안멈추고 계속 움직이나요?

2) 코드를 세 줄 (르탄이멈추기_로 표시. 14줄, 23줄, 43줄) 추가해 르탄이를 멈추려고 했는데, 실패했습니다. 원인은 무엇이고, 구현할려면 어떤 방식으로 코드를 작성해야할까요?


두 질문을 쭙고 싶습니다!





작성한 코드 및 에러 메세지

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


public class GameManager : MonoBehaviour
{
    public static GameManager Instance;
    public GameObject rain;
    public GameObject endPanel;
    public Text totalScoreTxt;
    public Text timeTxt;


    public Rtan rtan;  // 르탄이멈추기_ Rtan 컴포넌트 참조 변수 추가


    int totalScore;
    float totalTime = 3.0f;


    private void Awake()
    {
        Instance = this;
        Time.timeScale = 1.0f;
        rtan.direction = 0.05f; // 르탄이멈추기_ 재시작 시 르탄이 움직임
    }


    // Start is called before the first frame update
    void Start()
    {
        InvokeRepeating("MakeRain", 0f, 0.5f);
    }


    // Update is called once per frame
    void Update()
    {
        if (totalTime > 0f)
        {
            totalTime -= Time.deltaTime;
        }
        else
        {
            totalTime = 0f; // 위의 deltaTime 연산에서 오차가 발생할 수 있으므로 씀
            endPanel.SetActive(true);
            rtan.direction = 0// 르탄이멈추기_ 게임 종료 시 캐릭터 멈추기
            Time.timeScale = 0f; // 게임 정지
        }
        timeTxt.text = totalTime.ToString("N2");
    }


    void MakeRain()
    {
        Instantiate(rain);
    }


    public void AddScore(int Score)
    {
        totalScore += Score;
        totalScoreTxt.text = totalScore.ToString();
        Debug.Log(totalScore);
    }
}


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