- Home /
Access the renderer of a clones child object
Ok, I'm becoming desperate here after 2 h of googeling and probably making a really dumb mistake.
I'm instantiating arrows where the gameobject is the arrow with the model as a child. When something is hit after a time the arrow destroys itself (which is working fine) but I can't get any fading in because there is no renderer on my childobject. But there is.
I've tried stuff like:
MeshRenderer[] render = gameObject.GetComponentsInChildren<MeshRenderer>();
Transform childTransform = transform.FindChild("arrow");
MeshRenderer childRenderer = GetComponentInChildren<MeshRenderer>();
Transform childTransform = transform.FindChild("arrow");
and various other things. Also everything with gameObject. or transform. before. But the script is attached to the arrow gameobject so this shouldn't be necessary. Oh and of course I can't access it through the gameobject directly.
/edit parent prefab http://i.imgur.com/Bsw6Yrg.png child http://i.imgur.com/K2eYfYx.png
in the parent script I stop the arrow once it hits something so it sticks out and turn it to kinematic. later it gets destroyed. the only thing I want to add that doesn't work is a fading effect before it get's destroyed but I always get an error that there isn't a renderer.
Can you post a screenshot of your hierarchy view for these objects with the inspector showing first the parent object and another showing the child object that you are looking for the renderer on. You can do this by editing your question.
yes please more information. I'm having a bit of difficulty understanding what you're asking with just what you wrote.
I edited it in. Hope that makes it a bit clearer what my problem is.
What's the error specifically? What line of your code does the error happen on?
ins$$anonymous$$d of showing us a picture of your prefab, how about we see the actual object being instantiated in the game. Also share more of your script.
Answer by whydoidoit · Mar 28, 2013 at 09:05 PM
You have missed the child off the word renderer in this line:
childRenderer.material.color = Color.Lerp(renderer.material.color, Color.clear, 5f);
Should be:
childRenderer.material.color = Color.Lerp(childRenderer.material.color, Color.clear, 5f);
Not that this line makes much sense - it will immediately turn the color to Color.clear.
Lerp needs running over time with an incrementing value between 0 and 1 in the final parameter .