コード例 #1
0
    private void OnTriggerEnter(Collider other)
    {
        //  COLLECTING BATTERY
        if (other.gameObject.tag == "batery")
        {
            // other.gameObject.GetType
            Destroy(other.gameObject);
        }

        // COLLECTING HEALTH MUSHROOM
        else if (other.gameObject.tag == "healthMushroom")
        {
            Debug.Log("Health:" + currentHealth.ToString());
            healthShroom = other.gameObject.GetComponent <HealthMushroomClass>();
            if (currentHealth < maxHealth - healthShroom.GetHealth())
            {
                currentHealth += healthShroom.GetHealth();
            }
            else
            {
                currentHealth = maxHealth;
            }
            healthText.text = "Health: " + currentHealth.ToString();

            Destroy(other.gameObject);
            Debug.Log("Health:" + currentHealth.ToString());
        }

        // COLLECTING POISON MUSHROOM
        else if (other.gameObject.tag == "poisonMushroom")
        {
            Debug.Log("Sanity:" + currentSanity.ToString());
            poisonShroom   = other.gameObject.GetComponent <PoisonMushroomClass>();
            currentSanity -= poisonShroom.GetPoison();
            if (currentSanity <= 0)
            {
                SceneManager.LoadScene(1);
            }
            sanityText.text = "Sanity: " + currentSanity.ToString();
            Destroy(other.gameObject);
            Debug.Log("Sanity:" + currentSanity.ToString());
        }

        // ENEMY CLLISION
        else if (other.gameObject.tag == "enemy")
        {
            Debug.Log("Damage dealt to player");
            enemy           = other.gameObject.GetComponent <EnemyClass>();
            currentHealth  -= enemy.GetDamege();
            healthText.text = "Health: " + currentHealth.ToString();
            Destroy(other.gameObject);
        }
    }