Advertisement
FlyingFrog

Dialogue

Dec 26th, 2023
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using UnityEngine;
  2. using TMPro;
  3. using UnityEngine.UI;
  4.  
  5. public class Dialogue : MonoBehaviour
  6. {
  7.     [SerializeField] private TMP_Text _phrase;
  8.     [SerializeField] private DialogueNPC _npc;
  9.  
  10.     private int _currentIndex = -1;
  11.     public int CurrentIndex => _currentIndex;
  12.  
  13.     public void NextPhrase(PlayerInventory inventory)
  14.     {
  15.         if (_currentIndex < _npc.GetPhrasesCount() - 1)
  16.         {
  17.             _currentIndex++;
  18.         }
  19.         _phrase.text = _npc.GetPhrase(_currentIndex);
  20.         _npc.CheckInventory(inventory);
  21.     }
  22.  
  23.     public void SetNPC(DialogueNPC npc)
  24.     {
  25.         _npc = npc;
  26.     }
  27.  
  28.     public void ResetNPC()
  29.     {
  30.         _npc = null;
  31.     }
  32.  
  33.     public void ResetPhrases()
  34.     {
  35.         _currentIndex = -1  ;
  36.     }
  37.  
  38.     public DialogueNPC GetDialogueNpc()
  39.     {
  40.         return _npc;
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement