Page 1 of 3
Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 8:45 am
by olikante
Hey! I tried to find a topic that would describe my problem but I couldn't so I decided to write this post.
My project is a point-and-click type of game without a player in the scene (no walking character on the screen). Via dialogue, we get a quest to collect objects by clicking on buttons spread different scenes.
It works, even too good cause it reacts on ANY button. I tried to set up layers and tags by it doesn't work.
I'm using a selector for my mouse position placed on the main camera.
On the objects that suppose to be collected, I have:
- usable,
- increment on destroy script,
- dialogue trigger system.
I'm trying to solve it for two days, so I would appreciate any help.
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 8:53 am
by Tony Li
Hi,
What do you mean by "it reacts on ANY button"?
Do you mean an input button (e.g., left mouse button) or a UI button?
What if you set it up like this?
1. Selector: Remove Flower1B from OnSelectedUsable() event.
2. Collectible object: Remove Dialogue System Trigger. Configure Usable's Events > OnUse() Event to deactivate the GameObject.
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 9:02 am
by olikante
Oh, yes, sorry. UI button.
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 9:08 am
by olikante
Thanks for your help. I did what you suggested but there is no difference. The variable is incrementing when I click on any UI button.. Hm...
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 9:10 am
by Tony Li
If each collectible object has a UI button, you don't need to use the Selector and Usable components. Configure the UI Button's OnClick() event to deactivate the GameObject.
However, you want to use the Selector to show what's currently under the mouse cursor, you can keep the Selector and Usable. In this case, remove the Dialogue System Trigger, and remove any events from the Usable's OnUse() event. The Selector will only show the selection; it won't actually response to clicks since the UI Button will handle that.
I see that your Increment On Destroy component's Increment amount is 5. This means that when you click on a flower, it will add 5 to the variable. Is that what you intend? If not, try setting it to 1.
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 9:15 am
by olikante
It is set to 5 for testing reasons, but my problem is that I would like that variable to change only when I click on the button in the green frame, but it increments when I click on buttons in the pink frames.
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 9:18 am
by Tony Li
If the variable should only increment when the player clicks on the green area, what is the purpose of the UI Button? Can you remove it?
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 9:26 am
by olikante
It just makes it easier to communicate that click event to other scripts as well.
However, do you know what is the exact problem with the situation here?
Why is the variable reacts on each UI button even if they don't have any components connected to the dialogue system?
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 9:31 am
by Tony Li
I don't know. Maybe it's coincidence, and the UI button simply overlaps the area that's covered by the Usable. If that's the case, the UI button isn't doing anything, but clicking on the area around the UI button is, completely unrelated, causing the Selector to use the Usable.
What do you need to communicate to other scripts? Can you do the same thing with the Usable component?
Get rid of either the Usable component or the UI button. It sounds like having both of them is causing confusion. If you really need both of them, it's certainly possible to do. In that case, let me know why you need both.
Re: Variable increments when I press any button, not the ones I want to.
Posted: Sun Feb 21, 2021 9:42 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.