json를 활용 대화 데이터


[Serializable]
public class DialogueData
{
    public int DIdx;
    public string characterName;
    public string dialogue;
    public string position;
    public string imageSprite;
    public string uiType;
}

[Serializable]
public class DialogueInfo
{
    public DialogueData[] dialogueDatas;
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DataManager : MonoBehaviour
{
   public DialogueInfo dialogueInfo;

   public static DataManager instance;
   private void Awake()
   {
       if (instance == null)
       {
           instance = this;
           DontDestroyOnLoad(gameObject);
       }
       else
       {
           Destroy(gameObject);
       }
   }

   private void Start()
   {
       var dialogueJson = Resources.Load("JsonData/dialogueDatas") as TextAsset;
       if (dialogueJson != null)
       {
           dialogueInfo = JsonUtility.FromJson<DialogueInfo>(dialogueJson.ToString());
           Debug.Log("JSON 파일 로드 성공");
       }
       else
       {
           Debug.LogError("JSON 파일 로드 실패");
       }
   }
}

 

json 파일을 로드하고

dialogueinfo를 dialoguemanager에 전달하여 Didx(대화인덱스)에 따라 대화 출력


2D 모닥불 효과 만들기


모닥불

 

혹시나 나중에 필요하거나 이 글을 읽는 누군가가 저처럼 필요할수도 있기에 세팅을 공유합니다.

 

Start Lifetime 1~2

Start Speed 1~1.5

Start Size = 0.3

Start Rotation -15 ~ 15

Start Color 빨강(RGBA 255, 0, 0, 255, FF0000), 노랑(RGBA 255, 255, 0, 255, FFFF00)

 

 

Shape = Cone

Angle = 30

Radius = 0.3

 

좌측: 노랑(255, 255, 0) Alpha = 0

우측: 빨강(255, 0, 0)  Alpha = 255

 

 

 

추가로

하이어라키 우클릭 → Effects → Particle System Force Field 추가하여 기존 파티클 시스템에 자식으로 넣습니다.

 

 

End Range = 1.5

Strength = 0.2


플레이어 위치에 따른 밝기 조절


public Light2D bonfireLight;
    public Transform player;
    public float maxRange = 10f; // 최대 거리
    public float maxIntensity = 1.0f; // 최대 밝기
    public float minIntensity = 0.5f; // 최소 밝기
    void Update()
    {
        float distance = Vector3.Distance(player.position, transform.position);

        if (distance <= maxRange)
        {
            float t = 1 - (distance / maxRange);
            bonfireLight.intensity = Mathf.Lerp(minIntensity, maxIntensity, t);
        }
        else
        {
            bonfireLight.intensity = minIntensity;
        }
    }

 

현재 위치를 구해서 

 

최대 거리보다 작아질경우(플레이어가 다가올경우)

 

light2d의 intensity를 lerp 선형 보간 함수를 통해 조절

(t는 0과 1사이의 값을 선형보간한다, t가 0이면 minIntensity 1이면 maxIntensity반환)

 

bonfireLight에는 light2d가 있는 오브젝트를 할당해주고

 

player에는 이동할 캐릭터 오브젝트를 할당해준다.

 

+ Recent posts