Flash Mesh Renderer

Hey Unitarians,

So I have a small platform type game, and I want it so that when the character gets hit, he gains temporary invulnerability. I can make it so that he is invulnerable, but I want to show that to the player by turning the mesh renderer off and on very quickly. How would I do this via script? Also how would I make it so that the on/off thing stops after a 2 seconds so he remains solid?

The required code to make your object blink is:

blinking material

The code from this forum post is:

var blink : boolean = true;
function blink()
    var myRend:MeshRenderer = GetComponent(MeshRenderer);       //Apply the MeshRenderer component to the myRend variable
    var myState:boolean = true;         //Makes our state true
    while(blink)                        //While our state is true
        myState = !myState;             //Change our state to the oposite
        myRend.enabled = myState;       //Id our state is enabled, the renderer will be enabled. If our state is disabled, the rendeder will be disabled
        yield WaitForSeconds(0.25);     //Waits for 0.25 seconds

Now start your blink() coroutine from another coroutine where you can make that coroutine stop after 2 seconds. This coroutine will be like:

function makePlayerInvulnerable() {
    yield WaitForSeconds(2);

Call this makePlayerInvulnerable() coroutine from your script when player dies.

Just use these codes for logic purpose only.