
질문
(gameManager.cs)
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public GameObject rain;
public static GameManager I;
public Text scoreText;
int totalScore;
void Awake()
{
I = this;
}
// Start is called before the first frame update
void Start()
{
InvokeRepeating("makeRain", 0, 0.5f);
}
// Update is called once per frame
void Update()
{
}
void makeRain()
{
Instantiate(rain);
}
public void addScore(int score)
{
totalScore += score;
scoreText.text = totalScore.ToString();
}
}
(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(3.0f, 5.0f);
transform.position = new Vector3(x, y, 0);
type = Random.Range(1, 4);
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
{
size = 0.8f;
score = 1;
GetComponent<SpriteRenderer>().color = new Color(150 / 255f, 150 / 255f, 255 / 255f, 255 / 255f);
}
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);
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;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
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);
}
}
빗방울 애니가 잘 되다가, gameManager에서 코드를 넣고 저장해서 플레이 해보면, 빗방울이 화면에 안 보입니다, 이 부분이 공부하면서 계속 반복되어 지는 문제인데 제가 이해를 못하는 건지, 같은 문제가 계속 생깁니다. project 에서 gameManager 를 Hierarchy gameManage로 넣어줄 때는 Inspector에 잘 생성이 되다가, gameManager에 코드를 넣는 작업을 하면, 생성이 됐던 부분이 없어집니다.
강사님 영상과 똑같이 코드를 넣는데도 어디서 잘못된 건지 놓치고 제 눈에 보이질 않네요, 이 부분만 오늘 세번째 계속 플레이 해 가며 보고 있습니다...


위에서 처럼 생성 됐다가, 아래처럼 없어집니다.
이유를 모르겠네요-
