Exemplo n.º 1
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.layer == LayerMask.NameToLayer("Interactable"))
        {
            FloatingObjectScript floatingObjectScript = collision.gameObject.GetComponent <FloatingObjectScript>();
            if (floatingObjectScript != null)
            {
                floatingObjectScript.DisableAndMarkForReuse();

                if (StatManager.timeInLevel <= 3.5f)
                {
                    return;
                }

                if (floatingObjectScript.damage > 0 && StatManager.timeInLevel <= 6 && LevelManager.CurrentLevel == 0)
                {
                    return;
                }

                if (floatingObjectScript.hitSound != null)
                {
                    collisionAudio.clip = floatingObjectScript.hitSound;
                    collisionAudio.Play();
                }

                StatManager.obstaclesHitInLevel++;
                trash += floatingObjectScript.score;
                StatManager.trashCollectedInLevel += floatingObjectScript.score;

                if (shieldActive)
                {
                    return;
                }

                if (floatingObjectScript.damage > 0)
                {
                    health -= floatingObjectScript.damage;
                    StatManager.healthLost        += floatingObjectScript.damage;
                    StatManager.healthLostInLevel += floatingObjectScript.damage;
                }

                if (trash >= trashCapacity)
                {
                    SceneManager.LoadScene("Assets/Scenes/UI/ScoreScreen.unity");
                }

                trashScoreBoard.text = trash + "/" + trashCapacity;
            }
        }
    }