
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
그 복붙도 해보고 했는데 비를 맞아도 점수가 안 올라요






작성한 코드 및 에러 메세지
오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.
//오류메세지
MissingComponentException: There is no 'SpriteRenderer' attached to the "GameManager" game object, but a script is trying to access it.
You probably need to add a SpriteRenderer to the game object "GameManager". Or your script needs to check if the component is attached before using it.
UnityEngine.SpriteRenderer.set_color (UnityEngine.Color value) (at <30adf90198bc4c4b83910c6fb1877998>:0)
rain.Start () (at Assets/script/rain.cs:27)
//오류메세지
NullReferenceException: Object reference not set to an instance of an object
rain.OnCollisionEnter2D (UnityEngine.Collision2D coll) (at Assets/script/rain.cs:67)
//rain.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rain : MonoBehaviour
{
int type;
float size;
int score;
void Start()
{
//랜덤하게 x는 y는 00~00중에서 나와라
float x = Random.Range(50f, 550f);
float y = Random.Range(900f, 1000f);
transform.position = new Vector3(x, y, 0);
//위치 값 넣어줌
//물 사이즈 값
type = Random.Range(1, 4);
//물 사이즈 크기 설정
if(type == 1)
{
size = 50.5f;
score = 2;
GetComponent<SpriteRenderer>().color = new Color(100 / 255f, 100 / 255f, 255 / 255f, 255 / 255f);
}
else if(type == 2)
{
size = 100.0f;
score = 1;
GetComponent<SpriteRenderer>().color = new Color(130 / 255f, 130 / 255f, 255 / 255f, 255 / 255f);
}
else if(type == 3)
{
size = 70.8f;
score = 1;
GetComponent<SpriteRenderer>().color = new Color(150 / 255f, 150 / 255f, 255 / 255f, 255 / 255f);
}
else
{
size = 60.8f;
score = 1;
GetComponent<SpriteRenderer>().color = new Color(150 / 255f, 150 / 255f, 255 / 255f, 255 / 255f);
}
transform.localScale = new Vector3(size, size, 0);
}
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.5f;
float toward = 100.0f; //따라하다가 보니 캐릭 크기 기준이
//
//더라..
void Start()
{
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
toward *= -1;
direction *= -1;
}
if (transform.position.x > 505f)
{
direction = -0.5f;
toward = -100.0f;
}
if (transform.position.x < 38f)
{
direction = 0.5f;
toward = 100.0f;
}
// FixedUpdate 사용시 FixedUpdate로 이동!
transform.position += new Vector3(direction, 0, 0);
//좌우반전
transform.localScale = new Vector3(toward, 100, 100);
}
}
//gamemanager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public GameObject rain;
public Text scoreText;
int totalScore; //점수올리기
public static GameManager I; //싱글톤화(매니저는하나다)
void Awakw()
{
I = this;
}
void Start()
{
InvokeRepeating("makeRain", 0, 0.5f);
}
void Update()
{
}
void makeRain()
{
Instantiate(rain);
}
public void addScore(int score)
{
totalScore += score;
scoreText.text = totalScore.ToString();
}
}
