오늘 한일
1. 플레이어 체온 UI 제작.
2. 플레이어 퀘스트 초반 버전 구현.
3. 새로운 게임맵 제작
1. 플레이어 체온 UI제작.
기존에 만들어 두었던 체력, 목마름, 배고픔, 스테미나 칸 옆에 체온 UI를 만들어서 붙여두었다.
최대 값을 40으로 잡고 평소에는 사람의 체온인 36.5도로 유지되도록 설정했다.
모닥불, 낮과 밤 등의 조건에 따라서 변하게 하고 싶었지만 그 부분들은 아직 팀원들이 작업중이였기 때문에 지금 할 수 있는 물에 젖은 경우 체온이 떨어지는 기믹만 먼저 만들었다.
먼저 물에 들어가는 사실을 체크하기 위해 물에 BoxCollider를 달아두고, IsTrigger를 켜둔다. 그리고 물에 젖는 것을 체크할 코드를 만들어준다.
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Unity.VisualScripting;
using UnityEngine;
public class WetConditionController : MonoBehaviour
{
private PlayerConditions playerConditions;
private Coroutine dryCoroutine;
private void Awake()
{
playerConditions = GetComponent<PlayerConditions>(); //현재 player에 달려있는 playercondition 가져오기
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.layer == LayerMask.NameToLayer("Water"))
{
Debug.Log("물에빠짐");
if(dryCoroutine != null) StopCoroutine(dryCoroutine);
playerConditions.isWet = true;
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.layer == LayerMask.NameToLayer("Water"))
{
dryCoroutine = StartCoroutine(Dry());
}
}
IEnumerator Dry()
{
yield return new WaitForSeconds(10f);
playerConditions.isWet = false;
Debug.Log("물이 마름");
}
}
물에 들어갔다가 나오면 바로 마르는게 아닌 10초 뒤에 마르도록 만들었다.
원래는 Invoke를 이용해서 구현했지만 이렇게 만들경우 마르기 전에 다시 물에 들어가면 물에 들어가있는 도중 물이 마르기 때문에 문제가 있었다.
그래서 코루틴을 사용해서 중간에 물에 들어가면 끊어주는 파트를 추가해주었다.
2. 플레이어 퀘스트 초반 버전 구현.
게임을 시작하게 되면 왼쪽위의 퀘스트 창 생성.
퀘스트 완료 시 퀘스트 완료 문구로 변경
퀘스트를 관리하기 위해 퀘스트 매니저 생성.
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class QuestManager : MonoBehaviour
{
public TMP_Text questText;
[HideInInspector] public bool Fishing;
[HideInInspector] public bool Drink;
[HideInInspector] public int QuestCount;
public static QuestManager Instance { get; private set; }
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(gameObject);
}
ResetCount();
}
void ResetCount()
{
Fishing = false;
Drink = false;
}
void Start()
{
DrinkWaterQuest(Drink);
}
public void DrinkWaterQuest(bool clear)
{
questText.text = "물가로 가서 물 마시기";
if (clear)
{
questText.text = "퀘스트 완료!";
Invoke("EndDrinkQuest", 3f);
}
}
void EndDrinkQuest()
{
FishingQuest(Fishing, QuestCount);
}
public void FishingQuest(bool clear, int count)
{
Debug.Log("Fishing");
questText.text = "낚시하기 (" + count + "/6)";
if (clear)
{
questText.text = "퀘스트 완료!";
Invoke("EndFishingQuest", 3f);
QuestCount = 0;
//다음 퀘스트
}
}
void EndFishingQuest()
{
Ending();
}
// 기타 퀘스트들
public void Ending()
{
questText.text = "탈출하기";
}
}
퀘스트의 동작을 수행하는 부분에 퀘스트 메서드 삽입.
--중략--
//퀘스트
if(QuestManager.Instance.Fishing == false)
{
QuestManager.Instance.QuestCount++;
if (QuestManager.Instance.QuestCount == 6)
{
QuestManager.Instance.Fishing = true;
}
QuestManager.Instance.FishingQuest(QuestManager.Instance.Fishing, QuestManager.Instance.QuestCount);
}
--후략--
3. 새로운 게임맵 제작
https://www.youtube.com/watch?v=6WeS8dLgGIk
이 영상을 이용해서 맵을 만들어 봤다.
기존 사용하던 맵에서 크게 벗어나지 않는 방법으로 하고자 한다.
만들고 보니 지형이 평평한 곳이 적어서 별로 마음에 들지는 않았다. 새로 만들어봐야겠다.
'TIL' 카테고리의 다른 글
2023/12/21 TIL (0) | 2023.12.21 |
---|---|
2023/12/20 TIL (0) | 2023.12.20 |
2023/12/18 TIL (1) | 2023.12.18 |
2023/12/15 TI (0) | 2023.12.15 |
2023/12/14 TIL (ScriptableObject / 정규표현식) (0) | 2023.12.14 |