Priv's Blog

Programming Simple Functionality: Unit 4 - Gameplay Machanics) Lesson 4.3 - PowerUp and CountDown 본문

Unity Learn/Pathway: Junior Programmer

Programming Simple Functionality: Unit 4 - Gameplay Machanics) Lesson 4.3 - PowerUp and CountDown

Priv 2021. 7. 24. 18:12

출처

 

Lesson 4.3 - PowerUp and CountDown - Unity Learn

Overview: The enemy chases the player around the island, but the player needs a better way to defend themselves... especially if we add more enemies. In this lesson, we’re going to create a powerup that gives the player a temporary strength boost, shovin

learn.unity.com


 

 

1. 서언


(영상: 링크 참조)

 

Lesson 4.3 - PowerUp and CountDown - Unity Learn

Overview: The enemy chases the player around the island, but the player needs a better way to defend themselves... especially if we add more enemies. In this lesson, we’re going to create a powerup that gives the player a temporary strength boost, shovin

learn.unity.com


 


 

2. 파워업(Powerup) 준비 및 선택하기

여러분의 프로젝트에 완전히 새로운 게임 플레이 메커니즘을 추가하기 위해서, 플레이어에게 일시적인 초능력을 제공하는 파워업 오브젝트를 새로 추가할 것입니다.

 


(영상: 링크 참조)

 

Lesson 4.3 - PowerUp and CountDown - Unity Learn

Overview: The enemy chases the player around the island, but the player needs a better way to defend themselves... especially if we add more enemies. In this lesson, we’re going to create a powerup that gives the player a temporary strength boost, shovin

learn.unity.com


 

  1. Library에서 Powerup 오브젝트를 scene 안으로 드래그하고, 이름을 "PowerUp"로 바꾸신 뒤, 스케일&위치를 수정해주세요.
  2. 파워업(Powerup) 오브젝트에 Box Collider를 추가하고, Edit Collider를 클릭하여 오브젝트 크기에 딱 맞게 조정하신 뒤, "Is Trigger" 체크박스를 클릭해주세요.
  3. 새로운 "Powerup" 태그를 하나 만드시고 powerup 오브젝트에 적용해주세요.
  4. Powerup 오브젝트를 Prefabs 폴더로 드래그하셔서 새로운 "오리지널 프리팹"을 생성해주세요.

 


 

3. 충돌했을 때 파워업 삭제하기

파워업 아이템이 작동되도록 만들기 위한 첫번째 단계는, 플레이어가 아이템에 닿았을 때 아이템이 사라지도록 만들고 새로운 불리언 변수로 플레이어가 아이템을 먹었는지를 판별하도록 만드는 것입니다.

 


(영상: 링크 참조)

 

Lesson 4.3 - PowerUp and CountDown - Unity Learn

Overview: The enemy chases the player around the island, but the player needs a better way to defend themselves... especially if we add more enemies. In this lesson, we’re going to create a powerup that gives the player a temporary strength boost, shovin

learn.unity.com


 

  1. PlayerController.cs 안에 새로운 OnTriggerEnter() 메서드를 추가해주세요.
  2. 파워업 아이템과 충돌하였을 때 이를 삭제하는 other.CompaerTag("powerup") if-statement를 추가해주세요.
  3. public bool hasPowerup; 를 새로 작성하고 hasPowerup = true; 로 설정하여 여러분이 파워업 아이템과 충돌할 수 있도록 만들어주세요.

 

 


 

4. 적과 파워업 아이템 테스트하기

파워업 아이템은 매우 특별한 상황에서만 작동할 것입니다: 플레이어가 파워업 아이템을 획득하고 적과 충돌했을 때 - 그러므로, 여러분은 먼저 이 매우 특별한 조건을 테스트해야 합니다.

 


(영상: 링크 참조)

 

Lesson 4.3 - PowerUp and CountDown - Unity Learn

Overview: The enemy chases the player around the island, but the player needs a better way to defend themselves... especially if we add more enemies. In this lesson, we’re going to create a powerup that gives the player a temporary strength boost, shovin

learn.unity.com


 

  1. 새로운 "Enemy" 태그를 생성하시고 Enemy 프리팹에 적용해주세요.
  2. PlayerController.cs 안에 OnCollisionEnter() 함수를 추가해주세요.
  3. 적 태그와 haPowerup 불리언 값을 테스트하는 이중-조건 if문을 만들어주세요.
  4. Debug.Log를 사용해 제대로 작동하는지 검사해주세요.

 

private void OnCollisionEnter(Collision collision)
{
     if (collision.gameObject.CompareTag("Enemy") && hasPowerup)
     {
          Debug.Log("Collided with: " + collision.gameObject.name + " with powerup set to " 
          + hasPowerup);
     }
}

 


 

5. 파워업 아이템에 추가적인 넉백 효과 부여하기

파워업 아이템의 조건이 완벽하게 설정되었으므로, 이제 실제 파워업 능력을 프로그래밍할 준비가 되었습니다: 플레이어가 파워업 아이템을 먹은 상태에서 적과 충돌하면 적이 저 멀리 튕겨져 날아가야 합니다!

 


(영상: 링크 참조)

 

Lesson 4.3 - PowerUp and CountDown - Unity Learn

Overview: The enemy chases the player around the island, but the player needs a better way to defend themselves... especially if we add more enemies. In this lesson, we’re going to create a powerup that gives the player a temporary strength boost, shovin

learn.unity.com


 

  1. OnCollisionEnter() 안에 새로운 지역 변수를 선언하여 적의 Rigidbody 컴포넌트를 받아와 주세요.
  2. 플레이어로부터 방향 값을 얻어오는 새로운 변수를 선언해주세요.
  3. 새로운 powerupStrength 변수를 사용하여 에게 impulse force를 적용해주세요.

 

 


 

6. 파워업 카운트다운 루틴 제작하기

파워업 아이템 효과가 영원히 지속되면 적에게 불리할 것입니다. - 그러므로 여러분은 플레이어가 파워업 아이템을 획득하면 시작되고, 시간이 만료되면 파워업 능력이 사라지는 카운트다운 타이머를 프로그래밍하셔야 합니다.

 


(영상: 링크 참조)

 

Lesson 4.3 - PowerUp and CountDown - Unity Learn

Overview: The enemy chases the player around the island, but the player needs a better way to defend themselves... especially if we add more enemies. In this lesson, we’re going to create a powerup that gives the player a temporary strength boost, shovin

learn.unity.com


 

  1. IEnumerator PowerupCountdownRoutine() {}을 새로 추가해주세요.
  2. PowerupCountdownRoutine 안에서 7초를 기다리고, 파워업 효과를 비활성화해주세요.
  3. 플레이어가 파워업 아이템과 충돌할 때, 코루틴(coroutine)을 시작해주세요.

 

 


 

7. 파워업 인디케이터 추가하기

게임을 보다 게임답게 만들기 위해서는, 플레이어가 파워업 상태 여부를 명확히 알 수 있게 해주는 시각적인 인디케이터가 표시되도록 프로그래밍해야 합니다.

 


(영상: 링크 참조)

 

Lesson 4.3 - PowerUp and CountDown - Unity Learn

Overview: The enemy chases the player around the island, but the player needs a better way to defend themselves... especially if we add more enemies. In this lesson, we’re going to create a powerup that gives the player a temporary strength boost, shovin

learn.unity.com


 

  1. Library에서 Powerup 오브젝트를 scene으로 드래그하시고, 이름을 "Powerup Indicator"로 바꾸신 뒤, 스케일을 조정해주세요.
  2. inspector 안에서 "Active" 체크박스를 체크 해제해주세요.
  3. PlayerController.cs에서 public GameObject powerupIndicator 변수를 새로 선언하시고, Powerup Indicator 변수를 inspector 안에 할당해주세요.
  4. 플레이어가 파워업 아이템과 충돌했을 때, 인디케이터 오브젝트를 활성화, 파워업 아이템이 사라졌을 때는 비활성화되도록 만들어주세요.
  5. Update() 안에서 인디케이터의 위치를 플레이어의 위치 + 오프셋 값으로 설정해주세요.

 

 


 

8. 내용 복습


(영상: 링크 참조)

 

Lesson 4.3 - PowerUp and CountDown - Unity Learn

Overview: The enemy chases the player around the island, but the player needs a better way to defend themselves... especially if we add more enemies. In this lesson, we’re going to create a powerup that gives the player a temporary strength boost, shovin

learn.unity.com


 

- 새로 배운 기능들

  • 플레이어가 파워업 아이템을 획득했을 때, 시각적인 인디케이터가 나타나도록 만들기
  • 플레이어가 파워업 아이템을 획득한 상태에서 적과 충돌했을 때, 적이 튕겨져 날아가도록 만들기
  • 특정 시간이 경과된 이후에 파워업 능력과 인디케이터가 사라지도록 만들기

 

- 새로 배운 개념과 기술들

  • 디버그 연결
  • 지역 컴포넌트 변수
  • IEnumerators와 WaitForSeconds()
  • 코루틴(Coroutines)
  • SetActive(true / false)

 

- 다음 시간에 학습할 내용

  • 플레이어가 밀어낼 수 있는 적들의 물결을 생성해보겠습니다!

 


 


수고하셨습니다!


Comments