예제 #1
0
    // Update is called once per frame
    void Update()
    {
        UpdateLivesUI();
        if (isInvulnerable)
        {
            isRendererActive = !isRendererActive;
            if (invulFrameCount % numberOfFramesToToggle == 0 && r != null)
            {
                r.enabled = isRendererActive;
            }

            Physics.IgnoreLayerCollision(8, 9, true);  // Temporarily ignore collision between player and enemy
            Physics.IgnoreLayerCollision(10, 9, true); // Player and rocket
            currentInvulTime += Time.deltaTime;
            if (currentInvulTime > invulnerableTime)
            {
                r.enabled        = true;
                isRendererActive = true;
                invulFrameCount  = 0;
                Physics.IgnoreLayerCollision(8, 9, false);
                Physics.IgnoreLayerCollision(10, 9, false);
                isInvulnerable   = false;
                currentInvulTime = 0.0f;
            }
            ++invulFrameCount;
        }

        if (Input.GetKeyDown(KeyCode.Space) && isGameOver)
        {
            Debug.Log("Restarting game");
            CreatePlayerObj();
            currentLives = lives;
            managerScript.RestartGame();

            r.enabled        = true;
            isRendererActive = true;
            invulFrameCount  = 0;
            Physics.IgnoreLayerCollision(8, 9, false);
            Physics.IgnoreLayerCollision(10, 9, false);
            isInvulnerable   = false;
            currentInvulTime = 0.0f;

            isGameOver           = false;
            gameOverText.enabled = false;
        }
    }