Page 2 of 3
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 9:58 am
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?
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 10:30 am
by olikante
1. I created a quest about collecting (clicking on specific UI buttons in the scene) objects.
2. I defined a variable to track the quest's progress.
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.
5. When they clicked on enough buttons then they can go back to the quest giver and finish the quest.
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.
Let me know if sth is unclear.
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 10:39 am
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?
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 10:44 am
by olikante
Rather UI button.
I hope it is obvious that the flower in the green area is also a button.
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 1:07 pm
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.
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 1:46 pm
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:
But it does not work...
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 1:50 pm
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..
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 1:59 pm
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.
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 2:12 pm
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 (57.41 KiB) Viewed 100 times
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 3:37 pm
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.
I will try to rebuild the scene tomorrow. If it will help, I will let you know.
Thanks for your effort!