- Home /
boolean variable not changing in inspector
basically i need to change the bool variable isTalking to false so that when dialog with a character ends that character can attack but not before. The trouble I'm having is that the variable doesn't change in the inspector and so the enemy either always attacks or never attacks based on what i set the variable to in the inspector. Here are the relevant scripts public class DialogueManager : MonoBehaviour { public Text dialogueText; public bool isTalking;
private Queue<string> sentences;
// Start is called before the first frame update
void Start()
{
sentences = new Queue<string>();
}
public void StartDialogue(Dialogue dialogue)
{
Debug.Log("Starting conversation");
isTalking = true;
sentences.Clear();
foreach (string sentence in dialogue.sentences)
{
sentences.Enqueue(sentence);
}
DisplayNextSentence();
}
public void DisplayNextSentence()
{
if (sentences.Count == 0)
{
EndDialogue();
return;
}
string sentence = sentences.Dequeue();
Debug.Log(sentence);
dialogueText.text = sentence;
}
public void EndDialogue()
{
Debug.Log("End of conversation");
isTalking = false;
var canvas = GameObject.FindGameObjectWithTag("Canvas");
Destroy(canvas);
}
}
public GameObject SmallFireball; public GameObject LineOfFire;
private float fireRate = 4.0f;
private float nextFire;
private float attack;
public GameObject Player;
private float distance;
GameObject obj;
// Start is called before the first frame update
void Start()
{
nextFire = Time.time;
}
// Update is called once per frame
void Update()
{
obj = GameObject.FindGameObjectWithTag("Dialogue Manager");
var talking = obj.GetComponent<DialogueManager>().isTalking;
if (talking == false)
{
CheckIfTimeToFire();
}
}
public void CheckIfTimeToFire()
{
if (Time.time > nextFire)
{
distance = Vector3.Distance(Player.transform.position, transform.position);
attack = Random.Range(0, 20);
if (attack > distance)
{
Instantiate(LineOfFire, transform.position, Quaternion.identity);
}
else
{
Instantiate(SmallFireball, transform.position, Quaternion.identity);
}
nextFire = Time.time + fireRate;
}
}
}
Thanks for your help
Your answer
Follow this Question
Related Questions
Adding variables to inspector strings 1 Answer
Use Euler angles for Quaternion variable in the Inspector 1 Answer
Public Scene Variables not appearing in the inspector 2 Answers
Script with variable number of variables ? 1 Answer
Notes or Bubble Window for Variables in Inspector Giving Help? 3 Answers