- Home /
Trouble with prefabs and activating each other's scripts
Hi,
I have an issue which I can't seem to solve in regards to prefabs knowing when other prefabs have been deleted.
As an example I have a game manager that spawns 100 cubes. Each cube has a script attached that spawns a sphere above it when it spawns. Both cubes and spheres are prefabs. So far so good, we have 100 cubes with 100 sphere above them.
Now each sphere has a script attached that destroys it when it is clicked on. What I would like is for each of the cubes to then know that the sphere above it has been destroyed and spawn another one.
The trouble is that I can't seem to send a message to the cube below to let it know the sphere above had been destroyed.
I've tried the following:
1) Childing the sphere - can;t as both are prefabs and it gives an error 2) Actually getting the cube to shoot an invisible ball to check if the sphere is there - memory issues 3) numbering prefabs - but this got messy and the numbers add up quickly to over millions - currently all instantiated prefabs have the (Clone) bracket next to them.
Using the latest 5.3.4 C#
I simply need to let the cube know when the sphere has been destroyed.
Thanks for your help.
I'm still kind of new to this, so please let me know if my question is unclear or missing something to help you answer my question.
Answer by Zoogyburger · Apr 30, 2016 at 06:56 PM
Here's some psudo-code:
void OnClick()
{
Destroy(gameobject);
if(gameobject == destroyed ){
Spawn a new one!
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612075741im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Instantiate Pre-fab clone altered on Instantiate 2 Answers
Different prefab getting instantiated? 1 Answer
Replace instantiated objects in an array 1 Answer
how to call the animation of prefab 0 Answers