PlayerLife.Update C# (CSharp) Method

Update() public method

public Update ( ) : void
return void
    void Update()
    {
        if (killed)
        {

            //**CHANGE: Check if the player already isn't waiting to respawn. Add the points and continue.
            if (!waitingForRespawn)
            {
                this.gameObject.GetComponent<SpriteRenderer>().color = Color.white;
                this.gameObject.GetComponent<CircleCollider2D>().enabled = false;
                this.gameObject.GetComponent<PlayerMovement>().wasSeen = false;
                this.gameObject.transform.position = new Vector3(0,0,10);

                timeStamp = Time.time + respawnTime;
                waitingForRespawn = true;
            }
            //--------------------------------------------------------------------

            //**CHANGE: Enough time has passed to respawn
            if (Time.time > timeStamp)
            {

                //Move to new respawn location
                GameObject[] respawnPosition = GameObject.FindGameObjectsWithTag("Respawn");
                int randNum = Random.Range(0, 3);

                gameObject.transform.position = respawnPosition[randNum].transform.position;

                //** CHANGE: Render the sprite and make the player invincible.
                this.gameObject.GetComponent<SpriteRenderer>().enabled = true;
                this.gameObject.GetComponent<CircleCollider2D>().enabled = true;
                this.gameObject.GetComponent<PlayerMovement>().SendMessage("Start");

                waitingForRespawn = false; //Reset respawn variable and set invincible variable
                isInvincible = true;
                timeStamp = Time.time + invincibilityDuration; //Set timer for invincibility
                //---------------------------------------

                killed = false;
            }
            //--------------------------------------------

        }

        //**CHANGE: Invincibility Check
        if (isInvincible)
        {
            alternateColors(); //Flash!

            if (Time.time > timeStamp) //Timer has run out for invincibility
            {

                Debug.Log("NO LONGER INVINCIBLE");
                this.gameObject.GetComponent<Renderer>().material.color = Color.white; //Reset the color
                isInvincible = false; //You are no longer invincible!
            }
        }

        //--------------------------------
    }