Presentation is loading. Please wait.

Presentation is loading. Please wait.

모 바 일 게 임 제 작 한국IT전문학교 박재성.

Similar presentations


Presentation on theme: "모 바 일 게 임 제 작 한국IT전문학교 박재성."— Presentation transcript:

1 한국IT전문학교 박재성

2 5 게임 제작의 기초(2)

3 5.22 미사일 연속 발사 키/버튼을 누를 때 실행하는 함수 input.GetButtonDown(“Fire1”); //한번
input.GetButton(“Fire1”); //지속적으로 마우스 버튼을 누를 때 실행하는 함수 input.GetMouseButtonDown(1); //한번 input.GetMouseButton(1); //지속적으로

4 5.22 미사일 연속 발사 public class CsFighter : MonoBehaviour {
public GUISkin skin; // GUI Skin public Transform asteroid; // 운석 public Transform missile; // 미사일 프리팹 public Transform expBig; // 폭파 불꽃 큰 것 public AudioClip sndMissile; // 미사일 발사 사운드 Transform LPoint; // spPoint Left Transform RPoint; // spPoint Right GameObject LFire; // 왼쪽 불꽃 GameObject RFire; // 오른쪽 불꽃 bool canFire = true; // 미사일을 발사할 수 있는가? bool isDead = false; // 전투기가 폭파되었는가? int HP = 10; // 전투기 보호막 int score = 0; // 점수 int speed = 20; // 스피드 float fw = Screen.width * 0.08f; // 전투기의 폭

5 5.22 미사일 연속 발사 void Start () { //Spawn Point 찾기
LPoint = transform.Find("LPoint"); RPoint = transform.Find("RPoint"); //변수초기화 HP = 5; score = 0; isDead = false; }

6 5.22 미사일 연속 발사

7 5.22 미사일 연속 발사 void Update () { if (isDead) //전투기가 폭파되었으면 종료. return;
MoveFighter(); //전투기이동 ShootMissile(); //미사일발사 MakeAsteroid(); //운석만들기 }

8 5.22 미사일 연속 발사 void ShootMissile () {
if (Input.GetButton("Fire1") && canFire) { MakeMissile( ); } void MakeMissile () // 미사일 만들기 Instantiate(missile, LPoint.position, Quaternion.identity); Instantiate(missile, RPoint.position, Quaternion.identity); AudioSource.PlayClipAtPoint(sndMissile, transform.position);

9 5.23 yield와 Coroutine - 미사일의 지속적 발사를 지연 시키기 void ShootMissile () {
if (Input.GetButton("Fire1") && canFire) { StartCoroutine("MakeMissile"); } IEnumerator MakeMissile () canFire=false; // 미사일 만들기 Instantiate(missile, LPoint.position, Quaternion.identity); Instantiate(missile, RPoint.position, Quaternion.identity); AudioSource.PlayClipAtPoint(sndMissile, transform.position); yield return new WaitForSeconds(0.2f); //0.2초지연 canFire = true;

10 5.24 오브젝트 보이기/감추기 planeY를 추가해서 왼쪽(Lfire), 오른쪽(Rfire) 발사 위치를 설정한다.
Lfire를 만든 다음 Ctrl + D 를 눌러서 Rfire를 만든다. GameObject LFire; // 왼쪽 불꽃 GameObject RFire; // 오른쪽 불꽃 void Start () { LFire = transform.Find("LFire").gameObject; RFire = transform.Find("RFire").gameObject; LFire.SetActive(false); RFire.SetActive(false); //LFire.renderer.enabled = false; //RFire.renderer.enabled = false; }

11 5.24 오브젝트 보이기/감추기 MakeMissile()에 발사불꽃 보이기/감추기 부분 추가
IEnumerator MakeMissile () { //불꽃보이기 LFire.SetActive(true); RFire.SetActive(true); yield return new WaitForSeconds(0.2f); // 0.2초 간격으로 미사일 발사 //불꽃 감추기 LFire.SetActive(false); RFire.SetActive(false); canFire = true; }

12 5.25 운석 만들기 18/100 확률로 운석 만들기 void MakeAsteroid () {
if (Random.Range(0, 1000) > 980) { Instantiate(asteroid); }

13 5.26 전투기의 충돌 처리 전투기에 Rigidbody 추가 Use Gravity 속성 해제
운석의 Sphere Collider의 Is Trigger 항목을 체크 // CsFighter.cs 에 충돌 처리 void OnTriggerEnter (Collider coll) { if (coll.transform.tag == "ASTEROID") { // 운석 파괴 coll.SendMessage("DestroySelf", SendMessageOptions.DontRequireReceiver); HP--; if (HP <= 0) { StartCoroutine("DestroyFighter"); }

14 5.26 전투기의 충돌 처리 IEnumerator DestroyFighter () {
Instantiate(expBig, transform.position, Quaternion.identity); yield return new WaitForSeconds(1); //1초 지연 //전투기의 위치를 화면 밖으로 이동 transform.position = new Vector3(0, -10, -20); isDead = true; }

15 5.27 전역 변수와 점수 표시 CsFighter.cs 에 추가 void OnGUI () { // 화면의 중심 좌표 구하기
int w = Screen.width / 2; int h = Screen.height / 2; GUI.Label(new Rect(10, 10, 120, 50), “HP : “ + HP); GUI.Label(new Rect(w - 50, 10, 120, 50), “Score : “ + score); }

16 5.27 전역 변수와 점수 표시 운석이 명중되면 CsFighter.cs의 score 변수에 값을 넣는다
static public int score=0; void HitMissile (Vector3 pos) { // 스코어 100 증가 CsFighter.score += 100; } void DestroySelf () // 스코어 1000 증가 CsFighter.score += 1000;

17 5.28 게임 오버 처리 Play 버튼, Quit 버튼을 생성한다. Void OnGUI(){ … if (!isDead)
return; if (GUI.Button(new Rect(w - 60, h - 50, 120, 50), "Play Game")) { Application.LoadLevel("MainGame"); } if (GUI.Button(new Rect(w - 60, h + 50, 120, 50), "Quit Game")) { Application.Quit();

18 5.29 GUI Skin 사용하기 버튼과 레이블의 글꼴을 변경한다. 프로젝트 뷰에 Font와 GUI Skin 설치
GUI Skin의 Font, Button 등 필요한 부분 속성 설정 OnGUI() 함수가 있는 스크립트에서 GUISkin type의 전역 변수 선언 3)의 전역 변수에 프로젝트 뷰의 GUI Skin 연결 OnGUI()함수에서 GUI.skin = 3)의 변수 설정

19 5.29 GUI Skin 사용하기 글꼴 추가

20 5.29 GUI Skin 사용하기 GUI 폴더를 만들고 Create > GUI Skin 선택해서 GUI Skin을 하나 추가. 이름을 GUI Skin으로 변경 GUI Skin의 글꼴 설정 CsFighter.cs 에 GUI Skin 추가 public GUISkin skin; void OnGUI(){ GUI.skin = skin; }

21 5.29 GUI Skin 사용하기 전투기에 설정된 CsFighter.cs 의 GUISkin 변수에 Project뷰의 GUISkin을 할당한다.

22 5.30 Rich Text GUI에 출력할 문자열에 스타일을 추가 하는 기능 HTML태그 형식 사용
<size=“글자크기”>표시할 내용</size> <color=“컬러”>표시할 내용</color> <b>표시할 내용</b> <i>표시할 내용</i> void OnGUI () { string sHp = "<color=yellow><b>HP : ##</b></color>"; string sScore = "<color=#00ff00ff><b>Score : ##</b></color>"; GUI.Label(new Rect(10, 10, 120, 50), sHp.Replace("##", HP.ToString())); GUI.Label(new Rect(w - 50, 10, 120, 50), sScore.Replace("##", "" + score)); }


Download ppt "모 바 일 게 임 제 작 한국IT전문학교 박재성."

Similar presentations


Ads by Google