playMaker

Author Topic: I wan't to add a script to objects that creates in runtime!  (Read 1059 times)

Silicon Power

  • Full Member
  • ***
  • Posts: 186
I wan't to add a script to objects that creates in runtime!
« on: September 17, 2019, 07:59:37 AM »
Hi. I want to add a script to some game objects and that's easy with "add script" action but problem is those objects will generate randomly in runtime so I need to know how can I get and store all those game objects and then how should I add that script to all of them?  :-\

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: I wan't to add a script to objects that creates in runtime!
« Reply #1 on: September 17, 2019, 08:07:24 AM »
Hi when you create object, store then in a variable.
Then add to an array.

Then you can loop thru the array with array get next and place script on each object.

you can use build in array or array maker. below are 2 videos about them and you can find more on youtube :)



Silicon Power

  • Full Member
  • ***
  • Posts: 186
Re: I wan't to add a script to objects that creates in runtime!
« Reply #2 on: September 17, 2019, 08:33:46 AM »
Thanks. I can store those game objects inside an Array but know I need to figure out how can I get those game object by name from that array. there is two type on name in that array. 1- Cube 2-Sword. I want to add a different script for each name.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: I wan't to add a script to objects that creates in runtime!
« Reply #3 on: September 17, 2019, 08:37:06 AM »
Hi.
you could use multiple arrays so that when object created it is placed in the proper array.

or use tags and for example "Game Object Tag Switch" to know which type it is