playMaker

Author Topic: showing unit selected when clicked and hide it if you select a different unit  (Read 599 times)

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Within my unit prefab, I have a selected visual object.

a bool check controls hiding or showing this element.

At the start, I hide this object and when I click on the unit (layer units) I set the bool value to true.

So when chosen this unit will activate the visual object.

If I choose another prefab unit within the scene I wish to deactivate the current chosen one and activate the newly selected unit. Is there a way I can do this?

I have managed to get more than one prefab to take orders, each one will go to a chosen location playing the correct animations.

short clip:


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi,
Probably a good way would be to have a array (list) with the prefabs.
then on selection loop thru the list and enable/disable the selected / deselected

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Hi djaydino,

Thank you for your reply.

The unit would need to add itself to the array.

but I am unsure as to how to loop thru the list and enable/disable the selected/deselected.

Could you possibly give some more information, please?




djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi.
It probably best to use Array Maker (Array List) since its easier to access

there are multiple ways to do it, one would be :

have a array list with the prefabs, then when user selects one, store the object "Selected Object" and do :

state 1:
Set Bool "Reset" (true)

State 2 :
Array List Get next (use the "reset" variable, this is to make sure the loop start from the beginning)
Store the Game Object "Current Object"

State 3 :
Game Object Compare (compare "Current Object" with "Selected Object")
if True go state 4
if False go state 5

State 4 :
Set as selected (this depends on how you show your selection)

State 5 :
Set as not selected


colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Hey I found this tutorial on youtube


But thank you for your very detailed reply.


colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
I used a different approach in the end I choose to parent the selected visual to the selected unit. Also, I am using emerald AI 3.0 for the units now.


I am hoping to be able to give more types of commands to the units now that I have this much working without using playmaker array maker, but possibly that aspect is required.

djaydino, Can you advise, please?




djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi.
You can Broadcast events but for performance its not recommended.

in our game Dark light i have a gameobject called 'scene manager' in my 'level scenes'
On loading a level scene i set the scenemanager on a global variable (gameobject)
so its easy to reference.

on the 'scene manager' object i have several array lists and fsms (Data) which i can access.

you can search on youtube for Playmaker array (maker)
there are several tutorials for it :)