
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
게임메니저 스크립트
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public GameObject rain;
int totalScore;
private void Awake()
{
Instance = this;
}
// Start is called before the first frame update
void Start()
{
InvokeRepeating("MakeRain", 0f, 1f);
}
// Update is called once per frame
void Update()
{
}
void MakeRain()
{
Instantiate(rain);
}
public void AddScore(int score)
{
totalScore += score;
Debug.Log(totalScore);
}
}
레인 스크립트
public class rain : MonoBehaviour
{
float size = 1.0f;
int score = 1;
SpriteRenderer renderer;
void Start()
{
renderer = GetComponent<SpriteRenderer>();
float randomX = Random.Range(-2.5f, 2.5f);
float randomY = Random.Range(3.7f, 4f);
transform.position = new Vector3(randomX, randomY, 0);
int type = Random.Range(1, 4);
if (type == 1)
{
size = 0.6f;
score = 1;
renderer.color = Color.red;
}
else if (type == 2)
{
size = 0.8f;
score = 2;
renderer.color = Color.green;
}
else if (type == 3)
{
size = 1.0f;
score = 3;
renderer.color = Color.yellow;
}
transform.localScale = new Vector3(size, size, 1.0f);
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("그라운드"))
{
Debug.Log("충돌");
Destroy(this.gameObject);
}
if (collision.gameObject.CompareTag("Player"))
{
GameManager.Instance.AddScore(score);
Destroy(this.gameObject);
}
}
}
지난번 답변대로 클래스명 바꿔도 딱히 바뀌는게 없네요
좌측 하단 콘솔창에 아무 메세지가 안떠요
