imagefile => Texture Type = Sprite
order in Layer : 화면에 보이는 순서 결정
대화 만들기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class Dialogue
{
[TextArea]
public string dialogue;
public Sprite cg;
}
public class dialogue : MonoBehaviour
{
[SerializeField] private SpriteRenderer sprite_StandingCG;
[SerializeField] private SpriteRenderer sprite_DialogueBox;
[SerializeField] private Text txt_Dialogue;
private bool isDialogue = false;
private int count = 0;
[SerializeField] private Dialogue[] dial;
public void ShowDialogue()
{
OnOff(true);
count = 0;
isDialogue = true;
}
public void HideDialogue()
{
OnOff(false);
count = 0;
isDialogue = false;
}
private void OnOff(bool _flag)
{
sprite_DialogueBox.gameObject.SetActive(_flag);
sprite_StandingCG.gameObject.SetActive(_flag);
txt_Dialogue.gameObject.SetActive(_flag);
}
private void NextDialogue()
{
txt_Dialogue.text = dial[count].dialogue;
sprite_StandingCG.sprite = dial[count].cg;
count++;
}
void Update()
{
if (isDialogue)
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (count < dial.Length)
NextDialogue();
else
HideDialogue();
}
}
}
}