Hello,
Im trying to get my character to blink when he collides with an object if anyone can help?
I got him to change to the color RED but he’s not blinking and Im not sure what Im missing? hopefully someone can point me in the right direction or help with the code heres what I have so far as I scratch my head:
var other : GameObject;
var blinkRate : float = .1;
var howManyBlinks : float = 10;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "byte")
{
changeColor();
//enable color change
}
}
function changeColor()
{
for (howManyBlinks = 0; howManyBlinks < 10; howManyBlinks++)
{
yield WaitForSeconds(blinkRate);
other.renderer.material.color = Color.red;
}
}
It looks like you need to change back to the original color. You could save the original color then lerp the two or use invoke repeat to call the function a number of times. Inside the function save the color, change the color, assign the original color, then repeat. Just an idea.
for (var i:int = 0; i < howManyBlinks; i++)
{
yield WaitForSeconds(blinkRate);
other.renderer.material.color = Color.red;
yield WaitForSeconds(blinkRate);
other.renderer.material.color = Color.white;
}
I think this might be closer to what you want. By the way, it doesn’t really make sense for you to set howManyBlinks to 10 at the top if you’re going to set it to 0 at the beginning of your for loop. I’ve changed that too.
AWESOME !!!
Thank You very Much! and thinking about it
you are correct it doesn’t make sense to set it to 10 if Im going to start it at 0 in the beginning.
Im new to programming and didn’t realize you could call and have 2 different variables in the For Loop and it just Hit me WOW this opens my mind just a little bit more. Adding in the change of color again is sweet somewhere along the way I got lost, I forgot that this is a loop and it will simply run through both sets of colors then back to the original state. This is AWESOME.
Again I seriously appreciate the help and knowledge that comes with this
it helps a lot thank you Elveatles. And I thank you as well Black Mantis though a little beyond my scope there are no bad ideas 