커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
스스로 해결
2-6 수업 이후 게임오버가 안됩니다..
undefined주차
북마크
강*훈
댓글
2
추천
0
조회수
23
조회수
23
스스로 해결

2-5 수업을 진행 했을 땐 문제 없이 모든 게 잘 실행 되었습니다.

오늘 2-6 수업을 듣고 실행해보니 아래처럼 풍선에 square가 닿아도 게임오버 되지 않습니다..

스파르타 즉문즉답



그래서 로그를 출력해보았습니다..

square가 생성될 때 = '내린다!'

square가 풍선에 닿았을 때 = '충돌!'



square가 생성될 때 '내린다!' 라는 문구는 나오지만 square가 풍선에 닿았을 때 '충돌!' 이라는 문구는 로그에 기록되지 않네요..



balloon - Circle Collider 2D 세팅

스파르타 즉문즉답


shield - circle Collider 2D 세팅

스파르타 즉문즉답


Prefabs/square Rigidbody 2D, Box Collider 2D 세팅

스파르타 즉문즉답


gameManager Inspector 세팅

스파르타 즉문즉답


gameManager.cs 소스코드

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


public class gameManager : MonoBehaviour
{
    public GameObject square;
    public GameObject endPanel;
    public Text timeTxt;
    public Text thisScoreTxt;
    public Text maxScoreTxt;
    float alive = 0f;
    bool isRunning = true;
    public static gameManager I;


    void Awake()
    {
        I = this;
    }
    // Start is called before the first frame update
    void Start()
    {
        Time.timeScale = 1.0f;
        InvokeRepeating("makeSquare", 0.0f, 0.5f);
    }


    // Update is called once per frame
    void Update()
    {
        if (isRunning)
        {
            alive += Time.deltaTime;
            timeTxt.text = alive.ToString("N2");
        }
    }


    void makeSquare()
    {
        Instantiate(square);
    }


    public void gameOver()
    {
        isRunning = false;
        Time.timeScale = 0.0f;
        thisScoreTxt.text = alive.ToString("N2");
        endPanel.SetActive(true);


        if (PlayerPrefs.HasKey("bestScore") == false)
        {
            PlayerPrefs.SetFloat("bestScore", alive);
        }
        else
        {
            if (PlayerPrefs.GetFloat("bestScore") < alive)
            {
                PlayerPrefs.SetFloat("bestScore", alive);
            }
        }
        float maxScore = PlayerPrefs.GetFloat("bestscore");
        maxScoreTxt.text = maxScore.ToString("N2");
    }


    public void retry()
    {
        SceneManager.LoadScene("MainScene");
    }
}



혹시 Script/gameManager의 Inspector 세팅이 None인게 문제인가요?

스파르타 즉문즉답

오류 메세지도 안 뜨고 뭐가 문제인지 모르겠습니다..

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