- Home /
Dialogue system with index, children, and parent.
What I want is that when I press Y, the current gameobject deactivates and the gameobject below it activates. Then when the last gameobject is reached and Y is pressed, the parent is deactivated. I'm trying to make a Text panel similar to that of Harvest Moon 64 or any other game actually. Where the NPC talks in like 3-4 boxes and then it disappears. It's more like a dialogue box.
Hey there everyone, I need help with something that I think is pretty easy to do, but it has me stumped. So what I'm trying to achieve is a dialogue sequence. The way I'm doing this is by having one parent gameobject that holds all the UI Text elements. I have DialogueSequence1 as the parent which holds all the UI Text elements as children and they're called TextPanel_1, TextPanel_2, etc. There's going to be a varying amount of these TexPanels and what I want is that when the player presses Y, the TextPanel that is currently active now, deactivates and the next TextPanel below it in the hierarchy activates and so on and so forth. I'm guessing that the easiest way to do this would be with some sort of index type of code, but I am not familiar with how to do that, and the internet isn't being too helpful. To give you an idea, think of pressing the A button to move onto what the NPC is going to say next in any game. That's what I'm trying to achieve. Here's a model: NPC talks --> Player presses Y --> Next dialogue panels appears while the previous one deactivates --> so on and so forth until the last one --> on the last dialogue panel, the parent deactivates. This should work with just one text panel as well, if not I'll adjust. I have some code that I wrote and this is it. Feel free to work off of that if you'd like.
public GameObject ObjectToDisable;
public GameObject ObjectToEnable;
public GameObject TextParentToDisable;
public int TextCounterMax; //This should be how many text panels you have
int TextCounter; // Don't forget that this only happens when the GameObject is actually active
private void Update()
{
if (Input.GetKeyDown(KeyCode.Y))
{
NextPanel();
}
if (TextCounter >= TextCounterMax)
{
TextParentToDisable.SetActive(false);
}
}
public void NextPanel()
{
ObjectToDisable.SetActive(false);
ObjectToEnable.SetActive(true);
TextCounter += 1;
Debug.Log(TextCounter);
}
Your answer
Follow this Question
Related Questions
Disable one of child of parent gameobject 1 Answer
How to create a child object of an object with a specific tag? 1 Answer
Moving certain sprites in my animation causes weird slingshot effect 0 Answers
Modifying HingJoint2D in a child GameObject 0 Answers
Extremely confused with parent and child object system 1 Answer