카테고리 없음

유니티 심화 팀프로젝트 2일차

이황충 2024. 6. 4. 20:55

유니티 게임개발캠프 TIL 33일차

 

오늘은 어제 작성한 와이어프레임과 UML을 바탕으로 기능구현을 시작하는 날이다. 

우선 그전에 다같이 에셋 찾는 시간을 가졌다. 에셋을 찾는게 정말 쉽지 않은 것 같다. 

물론 유료에셋까지 가면 좋은 퀄리티의 많은 에셋들이 있겠지만

지금은 실력향상 차원에서 프로젝트를 진행하고 있어서 완성도 보다는 숙련에 초점을 맞춰야 될 것 같다. 

그래서 일단 최대한으로 찾고 더이상 늦어지면 안되니 각자 분배한 부분의 기능 구현을 진행했다. 

우선 팀장님이 이번 강의와 또 개인프로젝트의 내용을 참고해서 기본 뼈대 프로젝트를 배포해 주었다. 

그래서 조금 익숙한 스크립트 상태에서 추가할 부분들을 추가하는 방식으로 진행했다. 

 

나는 플레이어 관련한 부분들을 맡았다.

새로 추가할 것들로는 플레어의 정보, 스탯시스템, 체온시스템, 버프아이템 적용 그리고 퀵슬롯 등이 있다. 

오늘은 일단 플레이어의 정보와 스탯, 체온시스템을 구현했다. 

 

먼저 정보와 스탯시스템은 Status라는 스크립트를 하나 만들어서 플레이어의 능력치들을 작성했고

또 레벨업했을시 스탯포인트를 이용해 각 능력치를 올리는 부분도 작성했다.

이부분은 추후에 UI쪽과 결합해서 스탯창에서 올리는 방식으로 적용해주면 될것같다. 

using UnityEngine;

public class Status : MonoBehaviour
{
    public int level = 1;
    public int curExp = 0;
    public int maxExp = 100;
    public float attackPower = 10;
    public float defence = 0;
    public float handiCraft = 10;
    public float weightLimit = 100;       
    public float statusPoint = 0;

    private int expPerLevel = 100;
    private float attackPowerIncrease = 5f;
    private float defenceIncrease = 2f;
    private float handiCraftIncrease = 5f;
    private float weightLimitIncrease = 50f;       

    public void GetExperience(int amount)
    {
        curExp += amount;
        while (curExp >= maxExp)
        {
            LevelUp();
        }
    }

    private void LevelUp()
    {
        level++;
        curExp -= maxExp;
        maxExp += expPerLevel;
        statusPoint += 1;
    }

    public void IncreaseAttackPower()
    {
        if (statusPoint > 0)
        {
            attackPower += attackPowerIncrease; 
            statusPoint -= 1; 
        }
    }

    public void IncreaseDefence()
    {
        if (statusPoint > 0)
        {
            defence += defenceIncrease;
            statusPoint -= 1;
        }
    }
     
    public void IncreaseHandiCraft()
    {
        if (statusPoint > 0)
        {
            handiCraft += handiCraftIncrease;
            statusPoint -= 1;
        }
    }

    public void IncreaseWeightLimit()
    {
        if (statusPoint > 0)
        {
            weightLimit += weightLimitIncrease;
            statusPoint -= 1;
        }
    }
}

 

그 다음으로는 체온 시스템을 구현했는데 보통 서바이벌 게임처럼 밤시간대에 온도가 내려가서

플레이어의 주위에 열원이 없다면 저체온증으로 인해 체력이 조금씩 감소하는 기능을 구현했다. 

기존의 DayNightCycle 스크립트에 현재온도와 새벽시간대의 온도를 추가해서

새벽시간대의 범위를 설정해 그때는 현재 체온을 낮추는 방식으로 작성했다. 

[Header("Temperature")]
public float currentTemperature = 36.5f;
public float nightTemperature = 26f;    

void Update()
{
    time = (time + timeRate * Time.deltaTime) % 1.0f;

    UpdateLighting(sun, sunColor, sunIntensity);
    UpdateLighting(moon, moonColor, moonIntensity);
    UpdateTemperature(); //이 부분 추가

    RenderSettings.ambientIntensity = lightingIntensityMultiplier.Evaluate(time);
    RenderSettings.reflectionIntensity = reflectionIntensityMultiplier.Evaluate(time);
}

private void UpdateTemperature()
{
    if (time >= 0.8f || time <= 0.2f)
    {
        currentTemperature = nightTemperature;
    }
    else
    {
        currentTemperature = 36.5f; 
    }
}

public float GetCurrentTemperature()
{
    return currentTemperature;
}

이렇게 기존 DayNightCycle 스크립트에 추가해 주었다. 

 

그리고 이 내용을 처음엔 player스크립트에 직접 할당하려고했는데

Player의 체력을 제어하는 부분은 PlayerCondition스크립트에 있어서

 

public DayNightCycle dayNightCycle;

private float coldHealthDecay = 3f;

private void Start()
{
    dayNightCycle = FindObjectOfType<DayNightCycle>(); 
}

private void CheckCold()
{
    float currentTemperature = dayNightCycle.GetCurrentTemperature();
    if (dayNightCycle.currentTemperature < 28f && !isInvincibility)
    {
        health.Subtract(coldHealthDecay * Time.deltaTime);
    }
}

이렇게 플레이어 스크립트에 추가해 주었다.

 

아직까지 UI와 연결이 되지않아 디버그로그로 확인해보니 잘 적용 되는 것 같다.

내일은 버프아이템 적용과 가장 어려울거같은 퀵슬롯을 구현해 볼 예정이다. 

하지만 내일은 특강도 있어서 시간 할당을 잘해야 할 것 같다.