Виталий
Мастер
(1180),
на голосовании
3 месяца назад
using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro;
public class NPC : MonoBehaviour { public GameObject dialoguePanel; public TextMeshProUGUI dialogueText; public string[] dialogue; private int index;
public GameObject contButton; public float wordSpeed; public bool playerIsClose;
// Update is called once per frame void Update() { if(Input.GetKeyDown(KeyCode.F) && playerIsClose) { if (dialoguePanel.activeInHierarchy) { zeroText(); }
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class NPC : MonoBehaviour
{
public GameObject dialoguePanel;
public TextMeshProUGUI dialogueText;
public string[] dialogue;
private int index;
public GameObject contButton;
public float wordSpeed;
public bool playerIsClose;
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.F) && playerIsClose)
{
if (dialoguePanel.activeInHierarchy)
{
zeroText();
}
else
{
dialoguePanel.SetActive(true);
StartCoroutine(Typing());
}
}
if(dialogueText.text == dialogue[index])
{
contButton.SetActive(true);
}
}
public void zeroText()
{
dialogueText.text = "";
index = 0;
dialoguePanel.SetActive(false);
}
IEnumerator Typing()
{
foreach(char letter in dialogue[index].ToCharArray())
{
dialogueText.text += letter;
yield return new WaitForSeconds(wordSpeed);
}
}
public void NextLine()
{
contButton.SetActive(false);
if(index < dialogue.Length - 1)
{
index++;
dialogueText.text = "";
StartCoroutine(Typing());
}
else
{
zeroText();
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
playerIsClose = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
playerIsClose = false;
zeroText();
}
}
}
как сделать так, чтобы управление игроком блокировалось во время диалога? Была доступна только мышь, чтобы нажимать кнопку далее?