- Home /
Make enemy Flash when Hit
I'm looking for code that will make an enemy unit flash when hit for a secind and then return it to it's normal color.
Answer by noradninja · Oct 26, 2010 at 12:20 AM
var colors = new Color[2];
function OnCollisionEnter() {
renderer.material.color = colors[0];
yield WaitForSeconds(.5);
renderer.material.color = colors[1];
}
Drop this on your object. You will be able to define the color it flashes (color 0) and the non flashing color (color 1) in the Editor with the standard color picker. Make sure color 1 and your material color are the same, or it will look wrong.
Note: This doesn't work if the shader does not have a colour parameter (ie mobile diffuse)
Answer by Persona · May 05, 2010 at 03:33 AM
I attempted that but for some reason the code didn't work. In addition that code works on the assumption that collideColor variable has been set up, but seeing as that's not included, I can't imitate it.
Ins$$anonymous$$d of making a new answer to respond to a given answer you should use comments :)
Did you check the documentation? http://unity3d.com/support/documentation/
Here's what you're looking for I think. http://unity3d.com/support/documentation/ScriptReference/Renderer-material.html http://unity3d.com/support/documentation/ScriptReference/Renderer.html
Sorry, still adapting to this. I tried applying it but still nothing.