playMaker

Author Topic: UI buton firing twice[SOLVED]  (Read 1075 times)

TerraImagina

  • Playmaker Newbie
  • *
  • Posts: 33
UI buton firing twice[SOLVED]
« on: December 12, 2019, 06:35:04 AM »
Hello

After few days of researching I am stuck with a problem on one of my script

The script is for my menu, to select the next scene to load.
I made a button in the canvas, and each time there is a click it increment a variable "currentscene" and depending on the number, with a switch, play an animation to show or hide some element in the scene.
The problem is that the variable get incremented 2 times and the switch is lauched 2 times as well as seen on the screenshot.
I wonder where does the problem come from. Is it possible that the button launch multiple time per frames?
What is the best way to setup a simple button script ?

I have a scene with a piano, where user can play some note with touch, Should a canvas button be used or is there some better way to implement simple button mechanism with playmaker.

One last question. Is it possible to play an animation in reverse, or the only way is to create another animation.

Thank you !
« Last Edit: December 13, 2019, 07:39:32 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: UI buton firing twice
« Reply #1 on: December 12, 2019, 06:57:55 AM »
Hi,

 put a wait one frame before coming back to the state checking for mouse click, else you can get it several time that the use has clicked indeed.

using mecanim, your state can have a speed of -1, so yes you can play animation in reverse.

Bye,

 Jean

TerraImagina

  • Playmaker Newbie
  • *
  • Posts: 33
Re: UI buton firing twice
« Reply #2 on: December 12, 2019, 07:32:32 AM »
Awesome !
This solved all the issues I had, thank you so much !