오늘은 보스 스테이지를 제작하고
보스 스킬을 만들었다.
보스 Hp가 50 미만일 때 랜덤한 벽돌 블럭을 생성하고,
Hp가 30, 70일 때 플레이어의 시야를 가려 플레이를 방해한다.
BossBrick.cs
using System;
using UnityEngine;
public class BossBrick : Brick
{
[SerializeField] private GameObject endingObj;
private BossAttack bossAttack;
private EndingManager endingManager;
protected override void Awake()
{
base.Awake();
endingManager = endingObj.GetComponent<EndingManager>();
bossAttack = GetComponent<BossAttack>();
BossInit();
}
private void Start()
{
brickUI.UpdateBrickHPTxt(HP);
}
private void BossInit()
{
SetHP(100);
SetScore(100);
}
// 보스 HP에 따라 보스 Skill 실행
private void CheckBossHP()
{
// HP 70, 30 일 때 - Blind Skill
if (HP == 70 || HP == 30)
{
bossAttack.BlindSkill();
}
// HP 50일 때 - Shield Skill
if (HP == 50)
{
bossAttack.ShieldSkill();
}
}
private void BossDie()
{
endingManager.GameClear();
}
public void SetBreakBossBrickManager(BrickManager breakBrick)
{
brickManager = breakBrick;
}
protected override void BrickBreak()
{
BossDie();
brickManager.GetBrickScore(Score);
gameObject.SetActive(false);
}
protected override void OnCollisionEnter2D(Collision2D collision)
{
base.OnCollisionEnter2D(collision);
CheckBossHP();
}
}
BossAttack.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossAttack : MonoBehaviour
{
[SerializeField] private GameObject BlindSkillCanvas;
[SerializeField] private GameObject ShieldSkillCanvas;
[SerializeField] private BrickManager brickManager;
private void Awake()
{
brickManager = brickManager.GetComponent<BrickManager>();
}
public void BlindSkill()
{
StartCoroutine(WaitTime( 5f, BlindSkillCanvas));
}
public void ShieldSkill()
{
int breakBrickIdx = brickManager.SetIndex();
// 부서진 벽돌 블럭 개수가 0이상일 때만 실행
if (breakBrickIdx !=0)
{
StartCoroutine(WaitTime(2f, ShieldSkillCanvas));
List<int> idxs = new List<int>();
for (int i=0; i < breakBrickIdx; i++)
{
idxs.Add(i);
}
// 현재 부서진 벽돌 중 절반 부활시키기
for (int i = 0; i < breakBrickIdx / 2 ; i++)
{
int randomIndex = Random.Range(0, idxs.Count);
int createBrickIdx = idxs[randomIndex];
// 선택된 인덱스를 리스트에서 제거
idxs.RemoveAt(randomIndex);
brickManager.SetActive(createBrickIdx);
}
}
}
IEnumerator WaitTime(float time, GameObject obj)
{
obj.SetActive(true);
yield return new WaitForSeconds(time);
obj.SetActive(false);
}
}
'게임 개발' 카테고리의 다른 글
[Unity] 3D-Dungeon (0) | 2024.05.28 |
---|---|
[Unity] BrickOutGame - 완성 (0) | 2024.05.23 |
[Unity] BrickOutGame - 충돌 처리 (0) | 2024.05.20 |
[Unity] BrickOutGame - 오브젝트 풀링 (2) (0) | 2024.05.17 |
[Unity] BrickOutGame - 오브젝트 풀링 (1) (0) | 2024.05.16 |