playMaker

Author Topic: Canvas Button and GUI Button  (Read 1675 times)

kentcheung2000

  • Playmaker Newbie
  • *
  • Posts: 33
    • View Profile
Canvas Button and GUI Button
« on: May 12, 2018, 11:21:08 PM »
Hi,

I am new to playmaker and unity.  I want to create a button for touch screen game.  Do I use GUI buttons or Canvas button?  Are they similar or have difference?

Thanks.

KC

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4022
    • View Profile
    • jinxtergames
Re: Canvas Button and GUI Button
« Reply #1 on: May 13, 2018, 06:24:48 AM »
Hi,
Gui Buttons are outdated, you should use Canvas buttons.

to send an event with the button : press + in the On Click () section
Then under 'runtime Only' drop in the gameobject with the fsm.
(warning! if there are multiple fsms on an object you need to move the fsm with the event above all the other fsms in the inspector)
Then on 'No Function' select "PlayMakerFsm/SendEvent (string)"
Then in the field below, place the event name that you wish to trigger.

if you need multiple fsms to have a button connected on the same object,
Then its better to use some actions or playMaker Event Proxy Component


You can get ugui action on the Ecosystem (search for : ugui proxy full)

OR

You can wait for the Playmaker 1.9 version (which should be released any time now) which includes ui actions.

Broken Stylus

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: Canvas Button and GUI Button
« Reply #2 on: June 09, 2018, 03:12:01 PM »
I use the Event Trigger component, it's very fast and does wonders, although like all components that use references, it will detect only one FSM per game object (I haven't been able to send an event to several FSMs at once on a single targeted game object).
This component allows for much more control than being limited to just onClick.

uGUI is a good system, the canvas scaling system is fantastic, but if you plan on animating stuff, it's more complicated...

verybinary

  • Junior Playmaker
  • **
  • Posts: 81
    • View Profile
    • The Museum of Digital
Re: Canvas Button and GUI Button
« Reply #3 on: June 20, 2018, 01:42:43 PM »
Are you using the send event thing in the inspector option for the button?
try this
create fsm on button
start with blank state with one event "click"
"click" routes to state 2. state two triggers events on all the objects you want to be affected
in the inspector, in the On Click area, send event "click"

Broken Stylus

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: Canvas Button and GUI Button
« Reply #4 on: June 22, 2018, 07:34:26 AM »
I use the Event Trigger component, it's very fast and does wonders...
This component allows for much more control than being limited to just onClick.

https://docs.unity3d.com/Manual/script-EventTrigger.html

This component allows to to many things rather intuitively, like creating an event that will change a colour, a text or start a monobehaviour script.

However, beware!
As of Unity 2017, you cannot reorder the events in the list though; i.e. you can't move an event up or down the list.
This limitation is not important when doing things that don't require PlayMaker, but anything directly done through Unity's "native" functions will take precedence over PlayMaker.

So if you have a game object that you want to deactivate through an event such as GameObject.SetActive (false) and if you're also using another event such as PlayMakerFSM.SendEvent to send and event to that same game object (whatever the reason), the FSM won't have time to do anything.

FSMs seem to have something like a frame of lag when using proxies or the Event Trigger component.

Putting the event that "talks" to the FSM at the top of the Event Trigger's list of events circumvented that problem.
Because the event at the top of the list is going to be sent first.

Another solution is to add a second Event Trigger component that sends events to your FSM on the same game object.

Notice that the order of your components on the game object will matter too. So place the Trigger Event that sends events to a FSM above any other Trigger Event (you can drag and slide components, even if the Unity interface isn't giving you any visual clue that there's something going on).
« Last Edit: June 22, 2018, 12:09:38 PM by Broken Stylus »

Broken Stylus

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: Canvas Button and GUI Button
« Reply #5 on: September 29, 2018, 08:47:45 AM »
Hi, I’m Ajay Ahlawat  Retd. Colonel in Indian Army. I like to play Polo.

Select your main FSM, then add the action 'Delete self' and set the mode to "World coordinates".
Run once.
thx

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4022
    • View Profile
    • jinxtergames
Re: Canvas Button and GUI Button
« Reply #6 on: September 29, 2018, 09:05:45 AM »
Hi.
Done :) forgot to remove including posts :)

There are a couple ad spammers every week.
Main problem is that they are not bots, so its hard to stop them automatically :)
« Last Edit: September 29, 2018, 09:07:51 AM by djaydino »

Broken Stylus

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: Canvas Button and GUI Button
« Reply #7 on: December 30, 2018, 11:28:45 AM »
I know it's an old thread but here are some other tips regarding Event Trigger which I think needed to be added there.

If you read my posts above you already saw how bizarre that thing is. It really needs to be repeated that following Unity's logic of only one type of component per object, this event and input related component is not going to be able to interact with more than one FSM, and that FSM will be the first one you added to the game object (you better remember which one it was if you have a habit of adding several on a single game objects).

Now, it also happens that your game object might be child of a parent with a Canvas Group component on it. That's a very useful component but how it interacts with Event Trigger isn't outright intuitive.

It has several options including these two ones: Interactable and Blocks Raycasts.
The first option will neutralize all children that have components with an Interactable option too, like UI Button for example. It DOES NOT disable the game objects though.
However, this option has absolutely no effect on the Event Trigger, which somehow lives in its own world for some reason.
The only way to stop a child from registering inputs/events is to set Block Raycasts on false, so the child(ren) don't receive the raycasts (used for mouse or touch inputs).

There are actions to handle the Canvas Group component, including one that manages all its properties.