Ok so I have 3 GameObjects that are being used to instantiate objects. They are all called TargetSpawner_GO
I have the following script attached to them:
When the instantiated object is killed I use the following script:
Now my problem: How do I know where the instantiated object came from so I can spawn another one at the location where it was first instantiated from.
Right now they are all coming from the same object when they die.
asked Sep 14 '10 at 03:58 AM
You could create a variable, kept on the spawned instance, that stores which 'spawner' it belongs to.
On a script attached to the spawned instance (which I will refer to as 'scriptName'):
In SpawnAnother(), when you create the object, you would:
This sets the 'spawnOrigin' variable (on the spawned instance) to the GameObject that spawned it.
You would then use the spawnOrigin variable to SpawnAnother(), i.e.:
Without your full code, I can't post a complete snippet, but hopefully you'll be able to piece it together. Any questions, please ask.
answered Sep 14 '10 at 04:38 AM
The easiest would be to store the position (and rotation) of the object in the Start function, and use it to spawn the object:
(P.S. I am not sure why you had gameObject as parameter for instantiate - I am assuming here that you want to clone the attached object, so I replaced it with gameObject).