- Home /
script won't affect prefabs that were placed in the scene multiple times
I created an object that has a script attached to the top most empty game object with a light and particle system childed beneath it. It looks like this:
EmptyGameObject(script is here)
->ParticleSystem
->Light
I then made a prefab of this and placed several in the scene. For some reason the script seems to only be affecting the last prefab I put in the scene. Does anybody know why?
I'm having a hard time understanding what the difference is. I would have to use GameObject.Find() in order to get an object to call GetComponent() on. So I would run into the same problem, I would think.
//////////////////////////////////////////////////////////////////////////////////////////
private GameObject flameEmitter;
private GameObject flameLight;
// Use this for initialization void Start ()
{
flameEmitter = GameObject.Find("CandleFlame/flame1");
flameLight = GameObject.Find("CandleFlame/candleLight");
}
// Update is called once per frame void Update ()
{
Particle [] flameParticles= flameEmitter.particleEmitter.particles;
}
Answer by efge · Mar 03, 2011 at 06:52 PM
Do you use GameObject.Find in your script?
(All instantiated prefabs could have the same name.)
That's probably what it is. Is there something else I could use besides GameObject.Find()?
Not sure why you use Find when you only want to access children or components of the EmptyGameObject. You could use GetComponent or GetComponentInChildren.