playMaker

Author Topic: Same prefabs spawn point problem![SOLVED]  (Read 924 times)

rizwanash

  • Junior Playmaker
  • **
  • Posts: 61
Same prefabs spawn point problem![SOLVED]
« on: July 15, 2019, 03:53:02 PM »
Hey guys!

I have same enemies in the scene as prefabs, multiple prefabs, How to get the last killed enemy's position in the scene, so i can instantiate something on that point like score or particle or anything.

Thanks
« Last Edit: July 16, 2019, 03:36:46 AM by jeanfabre »

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Same prefabs spawn point problem!
« Reply #1 on: July 15, 2019, 04:45:27 PM »
You need to find a way to determine what exactly is 'last'. You could count them up on spawn for example. Or maybe they are spawned based on a variable, and you know how many there are. Then you can deduct from a counter each time one dies (e.g. the enemy sends a global event when it dies), and to determine the last one. You could register enemies on spawn in an array, and when one dies, check the list if there's still another enemy in there.

You could always move one waypoint object to the location of a deceased enemy, and each time, the waypoint checks if there is still an enemy and if there is none, does spawn the Thing.

Here's one other idea. On spawn, the enemies are parented into one game object. When the enemy dies, it runs get child count on the parent and if the number is 1 (just itself alive), then it knows it's last, and could then spawn something on its own location. After that, it unparents itself (or is destroyed or whatever, maybe deactivated objects are also not counted, but I'm not sure). You can also count tags, and when they die, change the tag.
« Last Edit: July 15, 2019, 04:47:56 PM by Thore »

rizwanash

  • Junior Playmaker
  • **
  • Posts: 61
Re: Same prefabs spawn point problem!
« Reply #2 on: July 15, 2019, 05:05:30 PM »
Hey @Thore

Second options works like a charm actually, I dragged all in one parent object and then use Get Child and got their positions and then spawn objects there..

Thank YOU !!!