playMaker

Author Topic: Change value of different GO from single UI button  (Read 227 times)

Aaddiction

  • Full Member
  • ***
  • Posts: 108
    • View Profile
Change value of different GO from single UI button
« on: March 23, 2020, 10:24:43 AM »
I have a list of cars and I want to be able to upgrade components of those cars. Let's say power.

What would be the best approach to do that where we have one button called "power up" and we want to upgrade the only the current active car in the hierarchy list.

Thank you.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5082
    • View Profile
    • jinxtergames
Re: Change value of different GO from single UI button
« Reply #1 on: March 23, 2020, 12:47:22 PM »
Hi.
It more kind of depends on how you store the upgrades.

for the current selected you can just have it in a variable then on button press check selected car

Aaddiction

  • Full Member
  • ***
  • Posts: 108
    • View Profile
Re: Change value of different GO from single UI button
« Reply #2 on: March 24, 2020, 01:11:33 AM »
Thanks.

Well, I basically came to two possible approaches.

1. Broadcast a global event called "upgrade1, upgrade2, ..." and it's received from the active car.

2. Send event to the active game object, to and FSM with specific name, which game object is the active car stored in the current active game object from the array.

For the moment, I went with the first option.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5082
    • View Profile
    • jinxtergames
Re: Change value of different GO from single UI button
« Reply #3 on: March 24, 2020, 01:49:07 AM »
Hi.
Broadcast will check all objects if it can send a event so its not very efficient especially when you games grows (the more objects, the more to check)

arrays are way more efficient here.

you can have an array with all the cars (as object or as string (name))
then have another array with for example 'power'

1st you can get the active car from the array, and get the index.

then use that index on the 'power' array with 'array get' now you can add power to that index so that it matches with the car.

i would suggest to use array maker instead of the build in arrays.

As its more advanced and easier to reference + if you have easy save, you can save the arrays (actions for that are on the Ecosystem)

Here are some videos about array maker :




Aaddiction

  • Full Member
  • ***
  • Posts: 108
    • View Profile
Re: Change value of different GO from single UI button
« Reply #4 on: March 24, 2020, 03:05:35 AM »
Thanks a lot! :)