コード例 #1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        //ammo pickup
        if (other.gameObject.tag == "Ammo")
        {
            //space check
            if (totalPickUpCount < MAX_PICKUP_COUNT)
            {
                songCollection.PlayItemPickUp();

                //inc pickup count
                totalPickUpCount++;
                ammoSupplyCount++;

                //add to hud
                switch (ammoSupplyCount)
                {
                case 1:
                    ammoImage1.SetActive(true);
                    break;

                case 2:
                    ammoImage2.SetActive(true);
                    break;

                case 3:
                    ammoImage3.SetActive(true);
                    break;

                case 4:
                    ammoImage4.SetActive(true);
                    break;

                case 5:
                    ammoImage5.SetActive(true);
                    break;

                default:
                    Debug.Log("Error in Ammo pickup");
                    break;
                }

                //destroy pickup
                Destroy(other.gameObject);

                //update text
                inventoryCountText.text = totalPickUpCount.ToString();
            }
        }
        else if (other.gameObject.tag == "Health")
        {
            //space check
            if (totalPickUpCount < MAX_PICKUP_COUNT)
            {
                songCollection.PlayItemPickUp();

                //inc pickup count
                totalPickUpCount++;
                medicalSupplyCount++;

                //add to hud
                switch (medicalSupplyCount)
                {
                case 1:
                    healthImage1.SetActive(true);
                    break;

                case 2:
                    healthImage2.SetActive(true);
                    break;

                case 3:
                    healthImage3.SetActive(true);
                    break;

                case 4:
                    healthImage4.SetActive(true);
                    break;

                case 5:
                    healthImage5.SetActive(true);
                    break;

                default:
                    Debug.Log("Error in health Pickup");
                    break;
                }

                //destroy pickup
                Destroy(other.gameObject);

                //update text
                inventoryCountText.text = totalPickUpCount.ToString();
            }
        }
        else if (other.gameObject.tag == "Gas")
        {
            //space check
            if (totalPickUpCount < MAX_PICKUP_COUNT)
            {
                songCollection.PlayItemPickUp();

                //inc pickup count
                totalPickUpCount++;
                fuelSupplyCount++;

                //add to hud
                switch (fuelSupplyCount)
                {
                case 1:
                    fuelImage1.SetActive(true);
                    break;

                case 2:
                    fuelImage2.SetActive(true);
                    break;

                case 3:
                    fuelImage3.SetActive(true);
                    break;

                case 4:
                    fuelImage4.SetActive(true);
                    break;

                case 5:
                    fuelImage5.SetActive(true);
                    break;

                default:
                    Debug.Log("Error in Fuel Pickup");
                    break;
                }

                //destroy pickup
                Destroy(other.gameObject);

                //update text
                inventoryCountText.text = totalPickUpCount.ToString();
            }
        }
        else if (other.gameObject.tag == "Safehouse")
        {
            //set menu is open
            menuOpen = true;

            //open menu
            safeHouseMenu.SetActive(true);
        }
    }