Hello,
I created a dialouge system like in the following tutorial:
Everything worked fine until 20:28. That means that I have a working dialouge System, but the dialouge box is not hiding in the default state. A lot of people online posted that you can hide objetcs with e.g.
- TheObject.SetActive(true),
but this doesn’t work in my project. So I followed a different tutorial:
and watched the time code “Animator”. You just make two animations, one for the hidden box set to defalut and one showing the box and implement it to the code. Since my code is different than the code in the second tutorial, I just implemented the three red lines from the second tutorial where I thought it would make sense, but I actually know nothing about C#, I’m still a complete noob. I could start the game, but the dialouge box was still not hidden, but this message appeared after starting the dialouge:
"UnassignedReferenceException: The variable animator of DialougeManager has not been assigned.
You probably need to assign the animator variable of the DialougeManager script in the inspector. "
So I draged the dialouge box UI Element to the Animator in the Inspector. Now the dialouge box is still shown in default and I get a nice zoom effect after starting the conversation (exidently did something good ^^), but the box is still shown at default. Do I have to assign something else to the inspector or do you know an easier way to hide the dialouge box (.enabled=false also didn’t work)?
Thanks for your time
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class DialougeManager : MonoBehaviour
{
public Image actorImage;
public TextMeshProUGUI actorName;
public TextMeshProUGUI messageText;
public Image backgroundBox;
[COLOR=#ff0000] public Animator animator;[/COLOR]
Message[] currentMessages;
Actor[] currentActors;
int activeMessage = 0;
public static bool isActive = false;
public void OpenDialouge(Message[] messages, Actor[] actors) {
currentMessages = messages;
currentActors = actors;
activeMessage = 0;
isActive = true;
Debug.Log("Started conversation! Loaded messages: " + messages.Length);
DisplayMessage();
[COLOR=#ff4d4d] animator.SetBool("IsOpen", true);[/COLOR]
}
void DisplayMessage() {
Message messageToDisplay = currentMessages[activeMessage];
messageText.text = messageToDisplay.message;
Actor actorToDisplay = currentActors[messageToDisplay.actorId];
actorName.text = actorToDisplay.name;
actorImage.sprite = actorToDisplay.sprite;
}
public void NextMessage() {
activeMessage++;
if (activeMessage < currentMessages.Length) {
DisplayMessage();
} else {
Debug.Log("Conversation ended!");
isActive = false;
[COLOR=#ff0000]animator.SetBool("IsOpen", false);[/COLOR]
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isActive == true) {
NextMessage();
}
}
}