Пример #1
0
 //decrease health if player is hit by enemy
 private void OnTriggerEnter2D(Collider2D collision)
 {
     //decrease health
     if (collision.gameObject.tag == "Ghost") //if its a ghost
     //&& collision.gameObject.GetComponent<UnityGhost>()._behaviors != SteeringBehaviors.Seek) //and if its not going to its home location
     {
         if (isInvincible == false)
         {
             source.PlayOneShot(clip, 0.8f);
             StatManager.health -= 1;
             StartCoroutine(Hurt());
             StartCoroutine(Invincible());
         }
         if (StatManager.health <= 0)
         {
             SceneManagement.GameOver();
         }
     }
     //pickup key object
     else if (collision.gameObject.tag == "key")
     {
         source.PlayOneShot(clip2, 0.8f);
         StatManager.hasKey = true;
         Destroy(collision.gameObject);
     }
     //go to next level if player has key
     else if (collision.gameObject.tag == "stair")
     {
         if (StatManager.hasKey)
         {
             source.PlayOneShot(clip2, 0.8f);
             SceneManagement.LevelChange();
             StatManager.hasKey = false;
         }
     }
     else if (collision.gameObject.tag == "Exit")
     {
         if (StatManager.hasKey)
         {
             source.PlayOneShot(clip2, 0.8f);
             SceneManagement.LevelChange();
             StatManager.hasKey = false;
             StatManager.health = playerHealth;
         }
     }
 }