// Update is called once per frame
    void Update()
    {
        // handle invincibility
        if (isInvincible)
        {
            invincibleTimer += Time.deltaTime;

            // blink sprite
            if (invincibleTimer % 0.1f < 0.05f)
            {
                spriteRenderer.enabled = false;
            }
            else
            {
                spriteRenderer.enabled = true;
            }

            // end invincibility period
            if (invincibleTimer > invincibleTime)
            {
                invincibleTimer        = 0.0f;
                isInvincible           = false;
                spriteRenderer.enabled = true;
            }
        }

        // handle hit
        if (hit.IsHit())
        {
            TakeDamage(hit.GetDamage());
            hit.SetHit(false);
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        // handle game over
        if (lives == 0)
        {
            Destroy(gameObject);
        }

        // handle invincibility
        if (isInvincible)
        {
            invincibleTimer += Time.deltaTime;

            // blink sprite
            if (invincibleTimer % 0.1f < 0.05f)
            {
                spriteRenderer.enabled = false;
            }
            else
            {
                spriteRenderer.enabled = true;
            }

            // end invincibility period
            if (invincibleTimer > invincibleTime)
            {
                invincibleTimer        = 0.0f;
                isInvincible           = false;
                spriteRenderer.enabled = true;
            }
        }

        // handle hit
        if (hit.IsHit())
        {
            TakeDamage(hit.GetDamage());
            hit.SetHit(false);
        }


        // display canvas information
        DisplayHearts();
        DisplayLives();

        // Debug.Log(isInvincible);
    }