playMaker

Author Topic: Activate/Deactivate GameObjects with GUI buttons [SOLVED]  (Read 3768 times)

bazzajunior

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
    • Molber Games
Activate/Deactivate GameObjects with GUI buttons [SOLVED]
« on: June 10, 2015, 02:19:52 AM »
I've setup a scene where I have two game objects (yellow vehicle and red vehicle) which when active, follow the user's finger when they drag their digit on the screen. At the moment, this is done by creating two FSMs which are setup within a touch manager game object. RedFSM enables movement for the red vehicle, YellowFSM enables movement for the yellow vehicle.

I want it configured that when the user clicks on a specific button (button 1 or button 2), the chosen vehicle becomes active and the second vehicle becomes deactivated. Each stays where they are on the screen so that they can be re-enabled.

I've created the two buttons and added the necessary uGUI proxy and the new uGUI detect touch input from Ecosystem, both of which work great.

I attempted to setup a system in that when the game starts, the FSMs are disabled (using unchecked boxes within an 'Enable FSM' stored in RedFSM and YellowFSM). When the user clicks on one of the buttons, the chosen vehicle FSM becomes active via an 'EnableFSM' located within the chosen button.

Each button contains two 'Enable FSM' actions, one aimed at the chosen vehicle to enable and one aimed at the other vehicle to effectively, disable it. 

This works great initially. The game starts, both vehicles are deactivated and when a button is pressed, the chosen vehicle activates. The problem is, when the second button is selected, the new vehicle becomes active but the previous one doesn't deactivate.

I've built the above without using variables or an array and I'm starting to see obvious limitations but can't think where I'm best to put these changes in place.

If anyone has done something similar or could give me advice on how to fix the above, I'd be extremely grateful as I'm now at a junction where my game depends on this working.
« Last Edit: June 13, 2015, 12:52:36 AM by bazzajunior »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5546
    • View Profile
    • jinxtergames
Re: Activate/Deactivate GameObjects with GUI buttons
« Reply #1 on: June 10, 2015, 07:03:28 AM »
if you need to "swap" vehicle regularly i would not use Enable/ Disable
but i would rather :

Make a state that does nothing (idle) and set it as start and give it a "Global transition"

When it needs to be active use "send event" to activate the state that was the start state before with a "global transition"
and also send an event to the other car with the"global transition" on the start event.

greetings,

Dino

bazzajunior

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
    • Molber Games
Re: Activate/Deactivate GameObjects with GUI buttons
« Reply #2 on: June 11, 2015, 07:03:46 AM »
Hi Dino,

Thanks for that advice.

Where you mention "create a state that does nothing", is this to go into the vehicles FSMs?

I've taken some screengrabs of my vehicle and button setups which I've yet to edit. I know the button setup is a bit crappy so any advice is useful.

I'll go through and remove the 'Enable FSM' events action in each one.

Thanks again.


Barry

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5546
    • View Profile
    • jinxtergames
Re: Activate/Deactivate GameObjects with GUI buttons
« Reply #3 on: June 11, 2015, 08:20:24 AM »
yes it should go into the vehicles FSMs like this :



then use send event to disable/enable

bazzajunior

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
    • Molber Games
Re: Activate/Deactivate GameObjects with GUI buttons
« Reply #4 on: June 12, 2015, 02:44:55 AM »
Hi Dino,

Thanks for your help on this so far. It's definitely starting to come together now - and with less clutter in the FSMs.

I've got rid of all the 'Enable FSMs' and tweaked the 'GoTouchManager' GameObject that contains the vehicle FSMs as you suggested (see below). I've also tidied up the button manager.

The only glitch I have now is that the vehicles don't swap when the second button is pressed. It's similar to before in that both the vehicles are dormant and then when I press one button - one wakes up, when I press the second button the next wakes but the first continues to be active.

Is my problem that the vehicle movement FSM is specific to a vehicle or is there a way to deactivate the first vehicle when the next one is woken?

Thanks for your help on this, it really is much appreciated.


Barry

bazzajunior

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
    • Molber Games
Re: Activate/Deactivate GameObjects with GUI buttons
« Reply #5 on: June 13, 2015, 12:50:04 AM »
Figured it out!

Within the vehicle FSM, I made the 'deactivate' and 'enable' states global where originally I only made the 'enable' one a global transition.

By enabling both, I added two 'Send Event' actions within a button - one to reference the 'enable' on the 'red' vehicle and the 'deactivate' on the 'yellow' vehicle. This is then duplicated in reverse on the other button.

With this in place the swap works perfectly  :)