- Home /
change explosion color with detonator
I currently am making a special bomb in my game and I'd like the explosion to be the same color as the object being destroyed. I currently have the following code:
public GameObject tinyDetonator;
void Explode( Vector3 ePos ) {
tinyDetonator.renderer.sharedMaterial = renderer.sharedMaterial;
Instantiate( tinyDetonator, ePos, Quaternion.identity );
}
However, when I run this, I get the following error:
MissingComponentException: There is no 'Renderer' attached to the "Detonator-Tiny" game object, but a script is trying to access it. You probably need to add a Renderer to the game object "Detonator-Tiny". Or your script needs to check if the component is attached before using it.
Should I add a renderer (if so, how?) or is there some other way I can change the color of the explosion? Thanks!
Answer by Berenger · May 16, 2012 at 04:03 PM
Put that on the Detonator-Tiny's gameObject, in a start function
Detonator[] detonators = GetComponents<Detonator>();
foreach( Detonator D in detonators )
D.color = Color.red;
or in unityscript (Might be some mistakes, whatch out)
var detonators : Detonator[] = GetComponents.<Detonator>();
for( var D in detonators )
D.color = Color.red;
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Unity Freezing On Successful Detonator Explosion 2 Answers
Need material.color to revert. 3 Answers
Does Material.color, ParticleSystem.startcolor property clones/copies the material? 2 Answers
Changing the color at runtime is causing my material to look very different. 1 Answer