DiaManager.cs Alternate
NextMessageFunction keeps firing too much or something. I had to add in timers to cool it. Anyways, use this script if the first one doesn't work.
using System;
using System.Collections;
using System.Collections.Generic;
using Conversa.Runtime.Events;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.InputSystem;
public class DiaManager : MonoBehaviour
{
//UI GameObjects
public Image Portrait;
public TMP_Text ActorNameText;
public TMP_Text MessageText;
public RectTransform MessageBackgroundBox;
public GameObject ActorsPanel;
public GameObject DialogueUI;
//Input System Connection
private PlayerInput playerInput;
private bool allowNext = true;
private float timer;
private Action action;
//Storing the function from one script into this one
public delegate void NextMessageDelegate();
private NextMessageDelegate NextMessageFunction;
//Initial State of the Game
private void Start()
{
//I've put the playerInput component on the Player GameObject, hence the tag
playerInput = GameObject.FindWithTag("Player").GetComponent<PlayerInput>();
Hide();
NextMessageFunction = NextMessage;
}
private void NextMessage()
{
Debug.Log("Testing out this new thing, yo.");
}
//Hiding the Dialogue UI
public void Hide()
{
//First, check if the Dialogue UI is open in the scene
if (DialogueUI.activeInHierarchy == true)
{
DialogueUI.SetActive(false);
playerInput.SwitchCurrentActionMap("World");
}
}
public void HideAtEnd()
{
TimTheTimer(ControlUIAllowNext, 0.2f);
TimTheTimer(Hide, 0.25f);
}
public void Advance(InputAction.CallbackContext ctx)
{
if (ctx.started)
{
if (allowNext == true)
{
TimTheTimer(ControlUIAllowNext, 0.2f);
NextMessageFunction();
}
}
}
private void TimTheTimer(Action action, float timer)
{
allowNext = false;
this.action = action;
this.timer = timer;
}
private void ControlUIAllowNext()
{
allowNext = true;
}
private void Switchy()
{
//This switches to the non-UI actionmap created for the player moving in the world
}
private void Update()
{
timer -= Time.deltaTime;
if (timer < 0 && allowNext == false)
{
//Trigger the Action
action();
}
}
public void Show(string actor, string message, Sprite avatar, Action onContinue)
{
DialogueUI.SetActive(true);
playerInput.SwitchCurrentActionMap("UI");
MessageText.text = message;
//Check if avatar should be hidden
if (avatar != null)
{
UpdateActor(avatar, actor);
}
else
{
ActorsPanel.SetActive(false);
}
TimTheTimer(ControlUIAllowNext, 0.2f);
NextMessageFunction = () => onContinue();
}
private void UpdateActor(Sprite sprite, string actor)
{
ActorsPanel.SetActive(true);
Portrait.sprite = sprite;
ActorNameText.text = actor;
}
}
ALSO
DiaTrigger.CS Alternate
Change just this one function to have the new one created in the DiaManager.CS alternate script.
private void HandleEnd()
{
FindObjectOfType<DiaManager>().HideAtEnd();
}
Last updated