주녘공부일지

[ShootingGame] 6. 아이템과 필살기 구현하기 본문

GameEngine/Unity - Lecture

[ShootingGame] 6. 아이템과 필살기 구현하기

주녘 2022. 1. 29. 14:45
728x90

Scripts.zip
0.00MB

 

0. 준비하기

Item 오브젝트 생성 ( Collider, Rigidbody ) + 애니메이션 설정 + 프리팹화 + Item 스크립트 추가

 

class Item

 

- string 으로 타입을 저장하여 분류

- Rigidbody2D를 가져와 아이템을 * 1f의 속도로 떨어뜨림

- OnTriggerEnter2D로 BorderBullet 태그에 닿으면 객체를 파괴

 

BoomEffect 애니메이션 추가 ( 우측 이미지에선 Boom 오브젝트 활성화 상태이지만, 기본 설정 값은 비활성화 상태 )

 

- Boom Icon은 기본 셋팅 투명도 0

 ( 폭탄의 사용 가능 갯수를 투명도 0, 1로 나타내는 로직이기 때문 )

 

class GameManager - UpdateBoomIcon()

 

 

1. 충돌 로직

class Player - OnTriggerEnter2D 로직 추가

- Item 태그에 닿으면 실행할 로직을 추가 ( power, boom 은 최댓값에 도달하면 점수로 변환 )

 

class Enemy - OnHit() 로직 추가 ( public 변경 )

 

- 예외처리 내용 : 아이템 중복 드롭 방지

- 적 기체 파괴 시 랜덤한 확률로 아이템 드롭하는 로직 추가

 ( Instantiate()로 생성 )

 

 

2. 필살기

 

class Player - Boom() // Update()문에서 실행

 

- isBoomTime : 필살기 중복 사용 방지

- boomEffect (GameObject) 활성화 하고 1.5초 뒤에 비활성화

 

FindGameObjectsWithTag("태그이름")

- 태그이름의 태그를 가진 씬의 모든 오브젝트를 추출함 ( 다수 )

- 적 기체는 데미지를 주고, 총알은 무조건 파괴 ( for문으로 추출된 갯수만큼만 )
https://docs.unity3d.com/ScriptReference/GameObject.FindWithTag.html

 

Unity - Scripting API: GameObject.FindWithTag

Tags must be declared in the tag manager before using them. A UnityException is thrown if the tag does not exist or an empty string or null is passed as the tag. Note: This method returns the first GameObject it finds with the specified tag. If a scene con

docs.unity3d.com

 

+ FindGameObjectWithTag("태그이름") 

- 태그이름의 태그를 가진 씬의 오브젝트를 추출함 ( 단일 )

 

 

 

https://github.com/godgjwnsgur7/ShootingGame

 

강의 출처

https://www.youtube.com/watch?v=RLbcov_aGfo&list=PLO-mt5Iu5TeYtWvM9eN-xnwRbyUAMWd3b&index=6 

728x90