Hello!
So i have 2 scripts Dialogue and Npc.
On both of the scripts i have a public string[ ] sentences
I want to have multiple npc-s and when ever i go talk to the npc i want to load the Npc public string senteceses to Dialogue public string sentences.
For npc acctivation i am using raycasting and when ever it detecs the tag npc it starts the Dialogue script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Dialog2nd : MonoBehaviour
{
public TextMeshProUGUI textDisplay;
public string[] sentences;
private int index;
public float typingSpeed;
public GameObject continueButton;
public GameObject dialogUI;
public PlayerController PlayerCtrl;
void Start()
{
dialogUI.SetActive(false);
}
void Update()
{
if(textDisplay.text == sentences[index])
{
continueButton.SetActive(true);
}
}
public IEnumerator Type()
{
dialogUI.SetActive(true);
Debug.Log("Running corutine Type()");
foreach(char letter in sentences[index].ToCharArray())
{
textDisplay.text += letter;
yield return new WaitForSeconds(typingSpeed);
}
}
public void NextSetence()
{
continueButton.SetActive(false);
if (index < sentences.Length - 1)
{
index++;
textDisplay.text = "";
StartCoroutine(Type());
}else
{
textDisplay.text = "";
continueButton.SetActive(false);
PlayerCtrl.NpcUnInteract();
}
}
}
if (Input.GetKeyDown(Use))
{
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
if (Physics.Raycast(ray, out hit, range))
{
if (hit.collider.tag == "Npc" && IsInDialog == false)
{
NpcInteratct();
}
}
}
public void NpcInteratct()
{
StartCoroutine(dialog.Type());
LastMouseSens = mouse.mouseSens;
IsInDialog = true;
Time.timeScale = 1f;
Cursor.lockState = CursorLockMode.Confined;
mouse.mouseSens = 0f;
DialogueUi.SetActive(true);
}
Thank you but there is one more issue
so there is an error on StartCorutine(Type()); in the if statment
When i write StartCorutine(Type(dialogue)); it still gives me an error