Canvas에 Text를 만들고 Score를 작성
GameDirector 오브젝트를 만들고
GameDirector 스크립스 생성 후 오브젝트 안에 넣어준다
코트
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameDirector : MonoBehaviour
{
public Text txtScore;
private int totalScore;
public void AddScore(int score)
{
this.totalScore += score;
this.txtScore.text = totalScore.ToString();
}
}
코드 작성 후 tstScore 오브젝트를 오른쪽 하단에 GameDirector 오브젝트 안에 스크립트 밑에 넣어준다
코드
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletTrigger : MonoBehaviour
{
private GameDirector gameDirector;
private void Start()
{
this.gameDirector = GameObject.Find("GameDirector").GetComponent<GameDirector>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Enemy"))
{
Destroy(this.gameObject);
Destroy(collision.gameObject);
this.gameDirector.AddScore(10);
}
}
}
폰트와 폰트 사이즈 변경
*스코어판 완성
'Unity > 수업 내용' 카테고리의 다른 글
[2D]프로젝트Play&plane - 적기 피격 연출 (0) | 2021.10.14 |
---|---|
[2D]프로젝트Play&plane - 생명력 표시(3개) (0) | 2021.10.14 |
[2D]프로젝트Play&plane - 스케줄링 (0) | 2021.10.14 |
[2D]프로젝트Play&plane - 적기 생성 및 사망 (0) | 2021.10.14 |
[2D]프로젝트Play&plane - 레이어 된 배경 스크롤링 (0) | 2021.10.14 |