Destroy an Instantiated object
Hi there,
I have a prefab which is Instantiated into a parent object in the scene. What I would like to do is on an action - either touch or animation end - I would like the Instantiated object to be destroyed.
In the scene, many of the same Instantiated objects appear, so I was wondering if it can delete all with a reference to the main object.
Is this possible? I can't find a simple way to do this. I am not a coder, but have mainly used behaviours to do the work for me.
Many thanks in advance...
Rich
Hi, RICHARD COGGIN!
To delete all instantiated object at once you can go through the parent object's children and destroy them all.
Actually our Spectacles Depth Template has an example of the object spawner. It is really easy to set up, no code needed. It can be used outside of spectales context. Please see tutorial here
The Object Spawner takes care of instantiated objects, and deletes them as soon as their count reaches maximum.
Here is a project. I added two simple scripts on the spawned objects - behavior script that disables object on tap, and script that enables object back when spawned.
Let me know if there are any questions!
Best
Olha
PS. In order to make this template work as a regular lens please enable thsi settings on the ProjectSettings:
Hi There,
Thanks for your reply. I've had a look at the spectacles spawner script and am struggling to see how to adapt to my needs. If I explain the mechanic maybe you can help a little more?
So, I have a Behaviour Script in the Objects panel which when a Start Object Panel image is tapped on 'Touch End', Instantiates a number of prefabs over time.
In one of these object prefabs is a script which disables the behaviour script and brings up a game over panel/start again panel.
Trouble is, it's not disabling the script.
What I can't work out is how to disable the initial behaviour script, as at present I'm trying to stop it from instantiating the objects, but they still appear after.
So in short the script needs to instantiate the prefab, the prefab then can stop the script from instantiating any more and then the start again panel need to start up the next script.
I hope this makes sense!
Many thanks
Hi, RICHARD COGGIN
Maybe you could share your project and I could take a look ?
Best
Olha
That would be great! How do I send to you securely as it's a client project. Many thanks Olha.
Hi, RICHARD COGGIN . I created a private ticket some time ago for you to share a project, have you received it by any chance?