Variable increments when I press any button, not the ones I want to.

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable increments when I press any button, not the ones I want to.

Post by Tony Li »

Once you get it set up, I think you'll find that the final setup is quite simple.

What exactly do you want to happen?
olikante
Posts: 13
Joined: Sun Feb 21, 2021 8:23 am

Re: Variable increments when I press any button, not the ones I want to.

Post by olikante »

1. I created a quest about collecting (clicking on specific UI buttons in the scene) objects.

Image

2. I defined a variable to track the quest's progress.

Image

3. The user is entering a dialogue that starts a quest. It works.
4. The user needs to go to another scene and click on specific buttons to influence the variable.

Image

5. When they clicked on enough buttons then they can go back to the quest giver and finish the quest.

Image
Image

The problem is that if I click on the wrong button (not flower ;) ) under FlowerFields 2 component, under Canvas obviously, the variable is incremented as well.

Image
Image

Let me know if sth is unclear.
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable increments when I press any button, not the ones I want to.

Post by Tony Li »

What is the purpose of the UI buttons?

Do you want to increment the variable when the player clicks the green area (not UI button) or when the player clicks a UI button?
olikante
Posts: 13
Joined: Sun Feb 21, 2021 8:23 am

Re: Variable increments when I press any button, not the ones I want to.

Post by olikante »

Rather UI button.

I hope it is obvious that the flower in the green area is also a button.
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable increments when I press any button, not the ones I want to.

Post by Tony Li »

Got it. Then remove the Selector component. On the flowers, remove the Dialogue System Trigger and Usable components.

Keep the Increment On Destroy component.

Configure the Button's OnClick() event to disable the GameObject.
olikante
Posts: 13
Joined: Sun Feb 21, 2021 8:23 am

Re: Variable increments when I press any button, not the ones I want to.

Post by olikante »

I did all of it and the effect was the same. BUT! I found out that if I will set on the component "Increment On Destroy" Increment On "destroy" the thing is reacting on the button that takes us to another scene because it is destroyed. If Increment On is disabled, it interacts with anything that can be disabled, so with all the buttons on the scene. So it affect all the objects in the scene that cointains the script.

There needs to be a way to define objects that Increment On Destroy interprets only specific objects. I tried to do it here:

Image

But it does not work...
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable increments when I press any button, not the ones I want to.

Post by Tony Li »

Hi,

Your UI Button's OnClick() event should deactivate a GameObject (i.e., the flower containing that UI Button). The Increment On Destroy component should be on that GameObject.


Also, see How to: Change Scenes..
olikante
Posts: 13
Joined: Sun Feb 21, 2021 8:23 am

Re: Variable increments when I press any button, not the ones I want to.

Post by olikante »

Yes, I have exactly that setup.

My objects are appearing and disappearing exactly as I want. I have no problem with it.

Increment On Destroy is also on the object I want to use to influence my variable. But as I said, each UI button in the scene is influencing Increment On Destroy script. That is my problem.

I appreciate your help but it seems to miss my difficulty here. :(
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable increments when I press any button, not the ones I want to.

Post by Tony Li »

Increment On Destroy must be on the object that has the UI Button and that you are deactivating. Here's an example scene:

DS_TestPickFlowers_2021-02-21.unitypackage

The Flower is set up like this:
testPickFlowers.png
testPickFlowers.png (57.41 KiB) Viewed 97 times
olikante
Posts: 13
Joined: Sun Feb 21, 2021 8:23 am

Re: Variable increments when I press any button, not the ones I want to.

Post by olikante »

Thank you for creating the scene. Yes, it works in your example.
My buttons are set up exactly like yours, but it is not working. Probably the problem is somewhere else... Maybe I changed some setups or... I have no clue.

Image

I will try to rebuild the scene tomorrow. If it will help, I will let you know.

Thanks for your effort! :)
Post Reply