playMaker

Author Topic: Array List to Instantiate/Modify Prefabs  (Read 352 times)

PresentDayJosh

  • Playmaker Newbie
  • *
  • Posts: 2
    • View Profile
Array List to Instantiate/Modify Prefabs
« on: January 06, 2019, 04:08:21 PM »
Hi, getting back into programming and PlayMaker after a few years, so I'm not quite into the swing of figuring out some logic yet. Maybe you guys can help me out?

So I have an array list being generated with the Find Game Objects by Tag command, and then it is sorted. Mission accomplished! I feel so smart. Now here's where it falls apart:

I want each of these Game Objects to instantiate a UI button prefab as a child in my UI object in the hierarchy as well as add -150 to the Bottom Rect Transform every time a button is added.

Each UI button has a child with a TextMeshPro script which I want the text to be the name of the Game Object in the array.

Finally, when clicked, the UI button would then enable the FSM which I've already attached to the associated Game Object in the array..

Any help appreciated.
Thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4615
    • View Profile
    • jinxtergames
Re: Array List to Instantiate/Modify Prefabs
« Reply #1 on: January 07, 2019, 03:40:04 AM »
Hi.
To start i would not use 'Find Game Objects' action as it is 'heavy'

if you have a bunch of objects before starting the game, add them manually to the array.

if the are created @ runtime :
When they are created, you can store the object and then add to the array.
Then create next object. and do the same again.
on this time you can also get the name of the object and add to an array
and create a button for it.

For the buttons, you should look to some unity ui tutorials as you can set this up that a list of buttons will dynamically grow and without coding.
Try searching for "unity ui button list" on youtube.

Then on the Ecosystem you can find an action i made called "ui button from array index"

have the buttons (gameObjects) also in a list (you can also make a prefab button and create simultaneously with the objects).

Then use that array in the  "ui button from array index"
When one of the buttons is pressed you will get the index nr from the button and you can then use the index nr to get the object.