void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.name == "Player")
        {
            theEnergyManager.AddEnergy(energyToGive);
            gameObject.SetActive(false);

            if (energySound.isPlaying)
            {
                energySound.Stop();
                energySound.Play();
            }
            else
            {
                energySound.Play();
            }
        }
    }
Exemple #2
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.tag == "killbox")
        {
            /*
             * theGameManager.RestartGame ();
             *          moveSpeed = moveSpeedStore;
             *          speedMilestoneCount = speedMilestoneCountStore;
             *          speedupMilestone = speedupMilestoneStore;
             *
             *          deathSound1.Play ();
             *          //deathSound2.Play ();
             *          backgroundSound.Stop ();
             */
            deathSound1.Play();
            int heart = 0;
            if (PlayerPrefs.HasKey("Hearts"))
            {
                heart = PlayerPrefs.GetInt("Hearts");
            }
            int newHearts = heart - 1;
            if (newHearts <= 0)
            {
                newHearts = 0;
                theGameManager.RestartGame();
                moveSpeed           = moveSpeedStore;
                speedMilestoneCount = speedMilestoneCountStore;
                speedupMilestone    = speedupMilestoneStore;

                backgroundSound.Stop();
            }
            PlayerPrefs.SetInt("Hearts", newHearts);
            other.gameObject.SetActive(false);
            BlinkPlayer();
        }
        else if (other.gameObject.tag == "obstacle")
        {
            theOxygenManager.AddEnergy(energyToSubtract);
            powerDown.Play();
            other.gameObject.SetActive(false);
            BlinkPlayer();
        }
        else if (other.gameObject.tag == "obstacleplatform")
        {
            if (powerDown.isPlaying)
            {
                powerDown.Stop();
                powerDown.Play();
            }
            else
            {
                powerDown.Play();
            }

            theOxygenManager.AddEnergy(energyToSubtract);
            BlinkPlayer();
            thePlayer.transform.position = new Vector3(thePlayer.transform.position.x, thePlayer.transform.position.y + 0.5f, thePlayer.transform.position.z);
        }
        else if (other.gameObject.tag == "TeleportJungleWorld")
        {
            GameController.setArguments(moveSpeed, theScoremanager.scoreCount, theOxygenManager.energyCount, speedupMilestone, backgroundSound.time);
            SceneManager.LoadScene(level1);
            // Application.LoadLevel (level1);
        }
        else if (other.gameObject.tag == "heart")
        {
            int heart = 0;
            if (PlayerPrefs.HasKey("Hearts"))
            {
                heart = PlayerPrefs.GetInt("Hearts");
            }
            int newHearts = heart + 1;
            if (newHearts >= 5)
            {
                newHearts = 5;
            }
            PlayerPrefs.SetInt("Hearts", newHearts);
            other.gameObject.SetActive(false);
        }
    }