• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AlejandroBoss10 · Jun 28, 2018 at 03:31 AM · child objectparent-childindexdialoguedisable object

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);
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

88 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Enabling/Deactivating objects using keys. 1 Answer

When I set an object to be the child of another object, the child object does not anchor to the parent's position for about 25 seconds 1 Answer

Access tapped object's child's child's child,Unity access tapped object's child's child's child 1 Answer

Dialogue problems? 1 Answer

OnTriggerStay() Not Detected In Child Class 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges