커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
1-8 콘솔창에 스코어 표기가 안됩니다
undefined주차
북마크
윤*식
댓글
8
추천
0
조회수
16
조회수
16
답변 완료

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

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


게임메니저 스크립트

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);

    }

  }

}


지난번 답변대로 클래스명 바꿔도 딱히 바뀌는게 없네요

좌측 하단 콘솔창에 아무 메세지가 안떠요


스파르타 즉문즉답







취소
 공유
취소
댓글 0
댓글 알림
나의얼굴