playMaker

Author Topic: uGui button and "Mouse pick 2d" action wont work together [SOLVED]  (Read 1730 times)

bizilux

  • Full Member
  • ***
  • Posts: 171
    • View Profile
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:
  • user clicks on first button, to select building
  • user then clicks somewhere on screen where he wants that building
  • building gets placed at that location

now problem happens with this scenario:
  • user clicks on first button, to select building
  • user decides he doesnt want to place down that building
  • so, he clicks on second button to select another type of building
  • button is pressed, BUT ALSO, building that he firstly selected with button 1, gets placed underneath button 2 because that is where user just clicked

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.
« Last Edit: March 30, 2015, 04:52:18 PM by bizilux »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 13518
  • Official Playmaker Support
    • View Profile
Re: uGui button and "Mouse pick 2d" action wont work together
« Reply #1 on: March 29, 2015, 11:22:00 PM »
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

bizilux

  • Full Member
  • ***
  • Posts: 171
    • View Profile
Re: uGui button and "Mouse pick 2d" action wont work together
« Reply #2 on: March 30, 2015, 04: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.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 13518
  • Official Playmaker Support
    • View Profile
Re: uGui button and "Mouse pick 2d" action wont work together [SOLVED]
« Reply #3 on: March 30, 2015, 10:28:24 PM »
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