커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
retry시 메인씬 초기화가 나타나는 현상
게임개발 종합반 v8
1주차
북마크
이*율
댓글
7
추천
0
조회수
33
조회수
33
답변 완료

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

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


밑에 내용처럼 판넬을 통해 mainscene을 초기화하면 mainscene안에 있는게 게임매니저부터 UI까지 안 불러와집니다..

주말안에 대답은 해주시겠지 했는데 대답이 없어 눈물 한방울 흘리면서 다시 물어봅니다..


  1. SceneManager.LoadScene(SceneManager.GetActiveScene().name);로도 바꿔봤으나 문제는 풀리지 않고 똑같았습니다.
  2. 이번에 다시시작으로 빨간공이 나온걸로 보아 이전시간으로 돌아가는 것은 아닌 것 같습니다. 그냥 gamemanager부터 밑으로 없어집니다.


같은 시각 같은 파일입니다.



작성한 코드 및 에러 메세지

오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.

Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.


panel.cs

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


public class panel : MonoBehaviour
{
    public void retry()
    {
        GameManager.I.retry();
    }
}

GameManager.cs

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




public class GameManager : MonoBehaviour
{
    public GameObject rain;
    public GameObject panel;
    public static GameManager I;
    public Text scoreText;
    public Text timeText;
    int totalScore;
    float limit = 5f;


    void Awake()
    {
        I = this;
    }
    // Start is called before the first frame update
    void Start()
    {
        initGame();
        InvokeRepeating("makeRain", 0, 1f);
    }


    // Update is called once per frame
    void Update()
    {
        limit -= Time.deltaTime;
        if (limit < 0)
        {
            Time.timeScale = 0.0f;
            panel.SetActive(true);
            limit = 0.0f;
        }
        timeText.text = limit.ToString("N2");
    }


    void makeRain()
    {
        Instantiate(rain);
    }


    public void addScore(int score)
    {
        totalScore += score;
        scoreText.text = totalScore.ToString();
    }


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


    void initGame()
    {
        Time.timeScale = 1.0f;
        totalScore = 0;
        limit = 5.0f;
    }




}

rain.cs

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


public class rain : MonoBehaviour
{
    int type;
    float size;
    int score;
    // Start is called before the first frame update
    void Start()
    {
        float x = Random.Range(-2.7f, 2.7f);
        float y = Random.Range(3f, 5f);
        transform.position = new Vector3(x, y, 0);


        type = Random.Range(1, 5);
        if(type == 1)
        {
            size = 1.2f;
            score = 3;
            GetComponent<SpriteRenderer>().color = new Color(100 / 255f, 100 / 255f, 255 / 255f, 255 / 255f);
        }
        else if (type == 2)
        {
            size = 1.0f;
            score = 2;
            GetComponent<SpriteRenderer>().color = new Color(130 / 255f, 130 / 255f, 255 / 255f, 255 / 255f);
        }
        else if (type == 3)
        {
            size = 0.8f;
            score = 1;
            GetComponent<SpriteRenderer>().color = new Color(150 / 255f, 150 / 255f, 255 / 255f, 255 / 255f);
        }       
        else
        {
            size = 0.8f;
            score = -5;
            GetComponent<SpriteRenderer>().color = new Color(255 / 255.0f, 100.0f / 255.0f, 100.0f / 255.0f, 255.0f / 255.0f);
        }
        transform.localScale = new Vector3(size, size, 0);
    }


    // Update is called once per frame
    void Update()
    {
        
    }


    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "ground")
        {
            Destroy(gameObject);
        }


        if(coll.gameObject.tag == "rtan")
        {
            Destroy(gameObject);
            GameManager.I.addScore(score);
        }
    }
}


rtan.cs

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


public class rtan : MonoBehaviour
{
    float direction = 0.05f;
    float toward = 1.0f;


    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            toward *= -1;
            direction *= -1;
        }
        if (transform.position.x > 2.8f)
        {
            direction = -0.05f;
            toward = -1.0f;
        }
        if (transform.position.x < -2.8f)
        {
            direction = 0.05f;
            toward = 1.0f;
        }
        transform.localScale = new Vector3(toward, 1, 1);
        transform.position += new Vector3(direction, 0, 0);
    }
}
취소
 공유
취소
댓글 0
댓글 알림
나의얼굴