Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: bizilux on March 29, 2015, 05:25:20 PM

Title: uGui button and "Mouse pick 2d" action wont work together [SOLVED]
Post by: bizilux on March 29, 2015, 05:25:20 PM
hey all,

so lets get straight to the point. im trying to make RTS.

i used mouse pick 2d action, to get position of mouse, and then i convert that to world position, and then i create building at that position, when i press mouse down button. that worked just fine.

so now i created action bar in bottom of the screen, few uGui buttons to select different types of buildings.

this scenario works fine:

now problem happens with this scenario:

now problem is obviously in step #4, because "mouse pick 2d" action just ignores UI completely, it basically cant see that there is a button being clicked, its raycast just collides with ground, not with UI.

so i need a way for mouse pick 2d action to see that im clicking on UI button, and at that point mouse pick 2d action should not do anything, it shouldnt spawn building, it should just terminate. but right now it is as UI is completely invisible to mouse pick 2d action.
Title: Re: uGui button and "Mouse pick 2d" action wont work together
Post by: jeanfabre on March 30, 2015, 02:22:00 AM
Hi,

 The physics 2d and UI module are completly different. The UI has its own event system that you should use instead.

You'll need to reverse the logic and implement listeners on the UI gameobject you want to pick.

IF they are not buttons, use the UI "Event Trigger" component, implement the Pointer Click event, target a PlayMaker Fsm and call "PlayMaker.SendEvent" passing the event name as string. It's all visually done , no coding required here.
 

 Bye,

 Jean
Title: Re: uGui button and "Mouse pick 2d" action wont work together
Post by: bizilux on March 30, 2015, 07:51:57 PM
Jean thanks again, you are a god :)

it took me a while to figure out what you meant with event trigger component, i never used that stuff before.

for anyone that might have same problem, i attached how it looks like.

i had to also put in small delay of 0.1 sec into my FSM, because before event trigger script actually fired off, that fsm already completed and spawned object underneath button, it wasnt interrupted by global transition called by button, so small delay of 0.1 sec solves this.
Title: Re: uGui button and "Mouse pick 2d" action wont work together [SOLVED]
Post by: jeanfabre on March 31, 2015, 01:28:24 AM
Hi,

Good, I am glad you sorted this.

 re the delay. Try to use a "next frame event" action, it's a bit cleaner than a wait.

 Bye,

 Jean