반응형
SMALL

추가된 내용은 아래와 같다.
- enum 타입으로 포탈을 정의, 다음 스테이지로 가는 포탈의 추가
- 다음 스테이지로 가는 포탈의 경우 보스방의 특정 포인트에만 생성됨
- 생성된 포탈은 생성되는 애니메이션이 끝난뒤 (애니메이션은 아직 미정) colider active

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PortalController : MonoBehaviour
{
[SerializeField]
private DungeonSceneMain main;
public enum PotalType
{
Normal,
SafeRoomPortal,
BossPortal,
NextStagePortal
}
public PotalType type;
private void Awake()
{
this.main = GameObject.Find("DungeonSceneMain").GetComponent<DungeonSceneMain>();
if(this.type == PotalType.BossPortal)
{
this.GetComponent<Collider>().enabled = false;
this.StartCoroutine(this.WaitforGenerate());
}
}
private IEnumerator WaitforGenerate()
{
//다음 스테이지로 가는 포탈이 생성되는 애니메이션이 끝날때 까지 기다림
yield return new WaitForSeconds(3f);
this.GetComponent<Collider>().enabled = true;
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "Player")
{
if (this.type == PotalType.NextStagePortal)
{
Debug.Log("다음 스테이지로");
}
else
{
var parentPos = this.transform.parent.parent.position;
var protalName = this.transform.parent.name;
this.main.getPortalInfo(parentPos, protalName);
}
}
}
}
룸 랜덤 생성시 정해진 배열의 최소 50% 이상의 방이 만들어지도록 수정
DungeonSceneMain
while(this.generator.wholeRoomList.Count < this.generator.maxCol* this.generator.maxRow * 0.5f)
{
var maps = GameObject.FindGameObjectsWithTag("UsingRoom");
for (int i = 0; i < maps.Length; i++) { Destroy(maps[i]); }
this.generator.Init();
}
UIMapGenDirector (임시로 제작한 룸 재생성 버튼 클릭시)
this.btnMapReGen.onClick.AddListener(() =>
{
this.MapGenerator.wholeRoomList.Clear();
List<GameObject> maps = new List<GameObject>();
while (this.MapGenerator.wholeRoomList.Count < (this.MapGenerator.maxCol * this.MapGenerator.maxRow) * 0.5f)
{
maps = GameObject.FindGameObjectsWithTag("UsingRoom").ToList();
this.MapGenerator.Init();
}
this.main.spawnPlayer();
for (int i = 0; i < maps.Count; i++) { Destroy(maps[i]); }
this.AdjustFOV();
});
여기서 문제점이 하나 발생
앞으로 실제 게임에서는 있지 않을 기능이지만 맵을 재생성 해주는 버튼으로 맵을 재생성시 플레이어의 컴포넌트가 모두 풀려버리는 문제 발생
플레이어가 첫번째 스테이지에 생성되거나 다른 스테이지로 들어가면 플레이어를 생성, 위치를 변경해주는 코드는 이러하다.
this.spawnPlayer = () =>
{
var startRoomTrans = this.generator.wholeRoomList.Find(x => x.transform.name.Contains("Start")).transform;
if(!this.isPlayerSpawned)
{
this.player = Instantiate(this.player, startRoomTrans);
this.isPlayerSpawned = true;
}
else if (this.isPlayerSpawned)
{
this.player.transform.parent = startRoomTrans;
}
this.player.transform.localPosition = Vector2.zero;
this.UIdirector.currentPlayerMapPos = startRoomTrans.position;
};
여기서 플레이어는 시작 룸의 자식으로 들어가게 설계를 해두었는데 문제는 임시로 만든 맵 재생성 버튼을 클릭시 플레이어가 들어가 있던 룸까지 Destroy 되어 플레이어의 모든 컴포넌트가 꺼지는 문제가 있었다.
이걸 해결하기 위해 플레이어의 위치 이동은 맵이 모두 생성된 뒤 기존에 버려지는 맵들을 모두 부숴주고 플레이어를 최종 맵 배열에 넣어주는 방식으로 해결
반응형
LIST
'프로젝트 > 건즈앤 레이첼스' 카테고리의 다른 글
| [유니티 프로젝트] 맵 텔레포트 카메라 이동 및 맵 외곽의 void 만들기 (0) | 2023.03.26 |
|---|---|
| [유니티] 디자인 패턴 - 전략 패턴 (0) | 2023.03.26 |
| [유니티 프로젝트] 랜덤 생성맵 포탈 구현 (맵간의 이동) 및 미니맵 포지션 구현 (0) | 2023.03.19 |
| [유니티 프로젝트] 랜덤맵 미니맵 제작 (0) | 2023.03.18 |
| [유니티 프로젝트] A*알고리즘을 이용한 랜덤 맵 생성 .4 (0) | 2023.03.16 |