Hi all,
I will apologise for the lack of detail right now ( I will add code and more detail when I get home from work).
I am building an rpg, I have built a hp system and a dialogue system out of two separate screen space overlays, the hp system came first, but when i add the dialogue system it stops the hp bars (which follow the characters around) from appearing at all now. can these two overlays exist at the same time? I am new and have been relying heavily on guides found on popular video upload sites.
I will add code when I’m home, I just wanted to get the question out there while its clear in my mind.
thanks to all who read and especially all who would help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueManager : MonoBehaviour
{
public Text nameText;
public Text dialogueText;
public Animator animator;
private Queue<string> sentences;
// Start is called before the first frame update
void Start()
{
sentences = new Queue<string>();
}
public void StartDialogue (Dialogue dialogue)
{
animator.SetBool("isOpen", true);
nameText.text = dialogue.name;
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();
StopAllCoroutines();
StartCoroutine(TypeSentence(sentence));
}
IEnumerator TypeSentence (string sentence)
{
dialogueText.text = "";
foreach (char letter in sentence.ToCharArray())
{
dialogueText.text += letter;
yield return null;
}
}
void EndDialogue()
{
animator.SetBool("isOpen", false);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(CharacterStats))]
public class HealthUI : MonoBehaviour
{
public GameObject uiPrefab;
public Transform target;
float visibleTime = 10;
float lastMadeVisibleTime;
Transform ui;
Image healthSlider;
Transform cam;
//Start is called before the first frame updates
void Start()
{
cam = Camera.main.transform;
foreach (Canvas c in FindObjectsOfType<Canvas>())
{
if (c.renderMode == RenderMode.WorldSpace)
{
ui = Instantiate(uiPrefab, c.transform).transform;
healthSlider = ui.GetChild(0).GetComponent<Image>();
ui.gameObject.SetActive(false);
break;
}
}
GetComponent<CharacterStats>().OnHealthChanged += OnHealthChanged;
}
void OnHealthChanged(int maxHealth, int currentHealth)
{
if (ui != null)
{
ui.gameObject.SetActive(true);
lastMadeVisibleTime = Time.time;
float healthPercent = currentHealth / (float)maxHealth;
healthSlider.fillAmount = healthPercent;
if (currentHealth <= 0)
{
Destroy(ui.gameObject);
}
}
}
the dialogue system runs on 3 separate scripts. I dont know why adding dialogue system broke health ui system. could anyone help me please?
I’ve managed to fix this. seems that having 2 or 3 days away from the project allowed me to see clearly 