コード例 #1
0
    public void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Enemy"))
        {
            if (!powers.invencibility)
            {
                powers.StartInvulnerable();
                Die();
                RestartHealth();
            }

            else
            {
                enemy_ia Enemy = (enemy_ia)other.gameObject.GetComponent <enemy_ia>();
                KillEnemy(Enemy);
                powers.invencibility = false;
                map.ShieldUI.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 0.5f);
            }
        }

        if (other.gameObject.CompareTag("ExplodingTrap"))
        {
            damaged = true;
            if (!powers.invencibility)
            {
                OnMusicPlaying(explosionSound);
            }
        }

        if (other.gameObject.CompareTag("Food"))
        {
            Interactable newFocus = other.GetComponent <Item>();
            SetFocus(newFocus);
            focus = newFocus;
        }

        if (other.gameObject.CompareTag("Fire"))
        {
            map.FireUI.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f);
        }

        if (other.gameObject.CompareTag("Power-Up"))
        {
            Item newFocus = other.GetComponent <Item>();
            PowerUp = other.GetComponent <Item>();
            focus   = newFocus;

            if (newFocus.name == "Heart")
            {
                Powers power = newFocus.GetComponent <Powers>();
                if (numLifes < 3)
                {
                    numLifes++;
                    Lifes.transform.Find("Life_" + (4 - numLifes).ToString()).gameObject.SetActive(true);
                    newFocus.gameObject.SetActive(false);
                    newFocus.Interact();
                    RemoveFocus();
                }
            }
        }
    }