주녘공부일지

[ShootingGame] 10. 따라다니는 보조무기 만들기 본문

GameEngine/Unity - Lecture

[ShootingGame] 10. 따라다니는 보조무기 만들기

주녘 2022. 2. 3. 18:30
728x90

Scripts.zip
0.01MB

 

 

0. 준비하기

- Follower 오브젝트 3개 추가, FollowerBullet 프리펩 추가

- 보조 총알도 오브젝트 풀링 등록 ( class ObjectManager에 추가 )

 

 

1. 기본 작동 구현

class Follower

- class Player에서 필요한 변수와 함수를 가져와서 수정해서 사용

 

 

2. 팔로우 로직 ( 상속시키듯 구현 )

class Follower

Watch(), Follow() : 따라갈 위치를 갱신해주는 함수 // Update()문에서 실행

 

- Follower(0) 는 Player를 parent로 갖고, Follower(1)는 Follower(0)를, Follower(2)는 Follower(1)을 parent로 가져서 따라가게 만듬

 

#. Input Pos - 부모 오브젝트의 위치변동이 없다면, 자식도 이동하지 않음 (저장하지 않음)

 

#. Output Pos - 위치 정보를 프레임 단위로 큐에 저장하는데, 채워지기 전까지는 부모의 위치로 적용시키고, 데이터가 모두 채워지면 따라감 (채워진 갯수 == followDelay 값)

 

+ 팔로우딜레이 변수의 크기만큼 프레임 단위로 저장하기 때문에, 팔로우딜레이 변수의 크기가 클수록 따라가는 거리가 가 증가함 ( Update()문 - 프레임 단위로 실행 )

 

Queue - FIFO (First Input First Out) // 선입선출 자료구조

- Contains() : 큐에 요소가 있는지 여부를 확인하는 함수 ( 존재 시, true )

- Enqueue() : 큐에 데이터를 저장하는 함수

- Dequeue() : 큐의 첫 데이터를 빼면서 반환해주는 함수

https://godgjwnsgur7.tistory.com/24

 

[C#] Stack과 Queue ( 자료구조 )

컬렉션 클래스 : 닷넷 프레임워크가 제공하는 클래스 using System.Collections; 선언 시 사용 가능 1. Queue ( FIFO - First In First Out ) 먼저 입력된 값을 먼저 출력시키는 선입선출 컬렉션 https://docs.mic..

godgjwnsgur7.tistory.com

 

3. 파워 적용

class Player - OnTriggerEnter2D(), AddFollower()

- 파워 4,5,6 로직 추가, maxPower = 6으로 변경, 등

+ Fire() 함수의 case 3: - default: 로 변경

 

 

https://github.com/godgjwnsgur7/ShootingGame

 

GitHub - godgjwnsgur7/ShootingGame

Contribute to godgjwnsgur7/ShootingGame development by creating an account on GitHub.

github.com

 

강의 출처

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

 

728x90