- Home /
The question is answered, right answer was accepted
How to stop player movement during dialog?,I don't know what i can write after "if" to stop player movement during dialog
I don't know what i can write after "if" to stop player movement during dialog referring to another script responsible for it, please help :(
using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro;
public class piotrekDialog : MonoBehaviour { public TextMeshProUGUI textDisplay; public string[] sentences; private int index; public float typingSpeed; public GameObject continueButton; public playerMovement playerMovementScript;
void Start()
{
StartCoroutine(Type());
}
void Update()
{
if (textDisplay.text == sentences[index])
{
continueButton.SetActive(true);
}
if (textDisplay.text == sentences[index])
playerMovementScript.playerControlsEnabled = false;
else
{
playerMovementScript.playerControlsEnabled = true;
}
if (/* I don't know what to write here*/)
playerMovementScript.playerControlsEnabled = false;
else
{
playerMovementScript.playerControlsEnabled = true;
}
}
IEnumerator Type()
{
foreach (char letter in sentences[index].ToCharArray())
{
textDisplay.text += letter;
yield return new WaitForSeconds(typingSpeed);
}
}
public void NextSentence()
{
continueButton.SetActive(false);
if (index < sentences.Length - 1)
{
index++;
textDisplay.text = "";
StartCoroutine(Type());
}
else
{
textDisplay.text = "";
continueButton.SetActive(false);
}
}
},I don't know what i can write after "if" to stop player movement during dialog referring to another script responsible for it, please help :(
using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro;
public class piotrekDialog : MonoBehaviour { public TextMeshProUGUI textDisplay; public string[] sentences; private int index; public float typingSpeed; public GameObject continueButton; public playerMovement playerMovementScript;
void Start()
{
StartCoroutine(Type());
}
void Update()
{
if (textDisplay.text == sentences[index])
{
continueButton.SetActive(true);
}
if (textDisplay.text == sentences[index])
playerMovementScript.playerControlsEnabled = false;
else
{
playerMovementScript.playerControlsEnabled = true;
}
if (/* I don't know what to write here*/)
playerMovementScript.playerControlsEnabled = false;
else
{
playerMovementScript.playerControlsEnabled = true;
}
}
IEnumerator Type()
{
foreach (char letter in sentences[index].ToCharArray())
{
textDisplay.text += letter;
yield return new WaitForSeconds(typingSpeed);
}
}
public void NextSentence()
{
continueButton.SetActive(false);
if (index < sentences.Length - 1)
{
index++;
textDisplay.text = "";
StartCoroutine(Type());
}
else
{
textDisplay.text = "";
continueButton.SetActive(false);
}
}
}
Answer by logicandchaos · Feb 02, 2021 at 12:55 AM
How do you know when there is a dialog? how do you start a dialog? If you have no way of telling make a bool isDialogMode; then when you start your dialog you add in isDialogMode=true; and when you leave dialog you add isDialogMode=false; then in your if you put isDialogMode.