playMaker

Author Topic: How to switch objects with GUI buttons? [SOLVED]  (Read 4574 times)

Adam Z

  • Full Member
  • ***
  • Posts: 207
How to switch objects with GUI buttons? [SOLVED]
« on: May 08, 2013, 02:40:57 PM »
I'm creating a dice rolling app and I have 3 GUI buttons. Each button will allow the user to choose a dice, so there are 3 different dice objects.  After you select a dice, I would like the user to tap the screen and the dice they chose would drop from that tap location. 

I can setup a bunch of states, but I'm sure there is a cleaner way by using variables, maybe Booleans? Any advise would be greatly appreciated!
« Last Edit: May 09, 2013, 01:43:51 PM by adamzeliasz »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to switch objects with GUI buttons?
« Reply #1 on: May 09, 2013, 03:29:28 AM »
Hi,

 you will need both states and variables to achieve this.

 basically, your dice will be prefabs, and when you click on a gui button, you spawn ( using the "create Object") at the same position on screen than the button.

 could you detail maybe what problem you are actually having?

bye,

 Jean

Adam Z

  • Full Member
  • ***
  • Posts: 207
Re: How to switch objects with GUI buttons?
« Reply #2 on: May 09, 2013, 10:31:13 AM »
There is no problem. Just trying to understand a way to switch between dice using variables. Like I said I can use States to active and de-active each dice, but I thought it might be easier another way. So I'm looking for some advice. :)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to switch objects with GUI buttons?
« Reply #3 on: May 09, 2013, 10:55:17 AM »
Are you rolling more than one die at a time?


So you have 3 different dice objects.
You can make a GameObject variable called SelectedDice.
Use the GUI buttons to change the value of SelectedDice to whichever dice that button is associated with. If the user hits the button for Dice2 just have that guibutton change the SelectedDice variable to use Dice2 game object.
Set the tap to create the variable SelectedDice at that location.

Pretty simple, really.
« Last Edit: May 09, 2013, 10:57:21 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Adam Z

  • Full Member
  • ***
  • Posts: 207
Re: How to switch objects with GUI buttons?
« Reply #4 on: May 09, 2013, 11:11:38 AM »
I'm rolling each dice one at a time.

You mentioned "Use the GUI buttons to change the value of SelectedDice to whichever dice that button is associated with."

What action would I use to modify the variable 'SelectDice'?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to switch objects with GUI buttons?
« Reply #5 on: May 09, 2013, 11:43:54 AM »
Set Game Object

then choose the variable that you're storing the current dice selection in and assign to each different dice for each button.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Adam Z

  • Full Member
  • ***
  • Posts: 207
Re: How to switch objects with GUI buttons?
« Reply #6 on: May 09, 2013, 12:41:08 PM »
I have a global variable called "SelectedDice".

Attached to my camera is the FSM with all my GUI buttons. Each button has a Send Event to another State. On that new state has 'Set Game Object', variable is "SelectedDice" and the dice prefab is chosen. This state closes with a Finish to get back to the main FSM so you can choose another button.

I tried putting a 'Touch Event' on the main FSM where my GUI buttons are; with Began, and Send Event to Roll.  On the Roll state I have a 'Create Object', with the game object as the variable "SelectedDice".

When I tap the buttons flicker from visible to invisible and back again (probably because of the delay from Roll to the main FSM), but the Object doesn't get created. It seems like the variable isn't saving the selected game object from the button.

Thoughts?

Adam Z

  • Full Member
  • ***
  • Posts: 207
Re: How to switch objects with GUI buttons?
« Reply #7 on: May 09, 2013, 12:46:56 PM »
Actually it does work, its just that the Touch Event seems to be "on top" of the buttons, so when I tap on a button it's running the Touch Event, not the GUI. Whats a good solution to fix this?

Thanks again for your help!!

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to switch objects with GUI buttons?
« Reply #8 on: May 09, 2013, 01:08:47 PM »
I'm not familiar with Touch, but it seems that if you're using a generic Touch Event then you may need to separate them into Touch GUI and Touch Object.

Or, have a button that enters a state you can roll in by touching, when its done you're back to GUI only state.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Adam Z

  • Full Member
  • ***
  • Posts: 207
Re: How to switch objects with GUI buttons?
« Reply #9 on: May 09, 2013, 01:24:57 PM »
I really appreciate it Lane. I'll play around with it and see what solution works best. Thanks again!