유니티 오피셜 튜토리얼 2D Roguelike 관련


https://unity3d.com/kr/learn/tutorials/s/2d-roguelike-tutorial

위 튜토리얼을 따라 하다 몇가지 오류 발생해서 해결방법을 찾았기에 포스팅

튜토리얼 제작 당시가 4.X 버전 대였던것 같고.. 현재는 2018.x 버전이 최신 버전이라 발생하는 문제로 생각된다.

튜토리얼 에셋에 동봉된 [2D Roguelike Upgrade Guide 5x.pdf] 파일에 있는 내용을 적용하더라도 게임 진행이 정상적으로 안되는 문제가 발생

1. 게임이 Day 2 부터 시작하고 다음 레벨은 Day4
2. Day 4 에서 갑자기 food가 0이되고 종료
3. 적을 뚫고 지나감


구글링한 결과

1, 2번 오류는 Scripts/GameManager.cs 파일 수정해서 해결됨
SceneManager 변경사항 때문에 발생하는 문제로 생각됨

private int level = 0; // 1에서 0으로 수정

void Awake () {
    ...
    //InitGame(); 주석처리
}

//아래 내용은 [2D Roguelike Upgrade Guide 5x.pdf]에 있음
void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode) {
level++;
InitGame();
}

void OnEnable() {
SceneManager.sceneLoaded += OnLevelFinishedLoading;
}

void OnDisable() {
SceneManager.sceneLoaded -= OnLevelFinishedLoading;
}



3번 오류는
Enemy Prefab의 Box Collider 2D 사이즈가 0.0001 로 되어있어서 1로 수정해서 해결됨



참고한 글
https://forum.unity.com/threads/2d-roguelike-q-a.297180/page-22


Because off the changes in the SceneManager, they suggest we use OnLevelFinishedLoading for initialize the game,
well that's a good sugesttion but we have to do more changes in the code.
We must remove InitGame from the Awake because if we dont when we start the game we will have 2 boards loaded
(1 from Awake and from OnLevelFinishedLoading).
We only want InitGame on OnLevelFinishedLoading.
We must also change the private int level to start in zero or better remove any initialization because int default value is zero.

Thanks, this helped me to solve two of my bugs in gameplay:
- The game started on Day 2 and then next level was Day 4.
- On day four scene began with food points zero. After one move, sprite "starved".
I already thought it had something to do with loading scripts double time instead of single, but couldn't find the solution.

Still have some bugs left:
- i can move through enemy.
- And in player script: "The variable "hit" is declared but never used"

[SOLVED - left this here in case anyone else runs into the same issue]
I have *one* bug in my version - the player can walk through the enemies.
The player and enemies all have their collision set up, all are set to the BlockingLayer Layer,
and all have blockingLayer public variable correctly pointed to the BlockingLayer.
Looking through the code, the only line (as far as I can work out)
that is supposed to detect the player moving through enemies is this:
hit = Physics2D.Linecast (start, end, blockingLayer);

EDIT: Ha! As is often the way with these things, as soon as you ask for help with a bug, you spot it yourself....
I couldn't see anything wrong with the code so I tried flicking back and forth
between my enemy prefabs and the ones in the Completed/Prefab folder to see if
I could spot any difference. Somehow the Box Collider 2D Size X & Y had been
changed to 0.0001 on both my enemies! I have no idea how this happened...

Thanks! I searched two hours myself for this and couldnt find it!
This is exactly what i need to stop my sprite from moving through enemies!


댓글

이 블로그의 인기 게시물

Aseprite 스프라이트 슬라이스해서 개별로 저장 하는방법 ( How to save sprite split in Aseprite )

Unity Google Play Games Services 연동 오류로 인한 삽질 기록

Unity3D 에서 당신의 Pixel Art 게임을 Pixel Perfect 하게 만들기