
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
밑에 내용처럼 판넬을 통해 mainscene을 초기화하면 mainscene안에 있는게 게임매니저부터 UI까지 안 불러와집니다..
주말안에 대답은 해주시겠지 했는데 대답이 없어 눈물 한방울 흘리면서 다시 물어봅니다..


같은 시각 같은 파일입니다.
작성한 코드 및 에러 메세지
오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.
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);
}
}
