예제 #1
0
    private void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.tag.Equals("Soldier"))
        {
            if (SoldiersCollected < MaxSoldiers)
            {
                if (PickupSound != null)
                {
                    Vector3 soundLocation = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + 20.0f, gameObject.transform.position.z);
                    AudioSource.PlayClipAtPoint(PickupSound, soundLocation);
                }

                SoldiersCollected += 1;
                Destroy(collider.gameObject);
            }
        }
        else if (collider.gameObject.tag.Equals("Hospital"))
        {
            if (DropoffSound != null)
            {
                Vector3 soundLocation = new Vector3(0, gameObject.transform.position.y + 20.0f, 0);
                AudioSource.PlayClipAtPoint(DropoffSound, soundLocation);
            }

            HospitalController hospitalController = collider.gameObject.GetComponent <HospitalController>();
            if (hospitalController != null)
            {
                hospitalController.AddSoldiersCollected(SoldiersCollected);
            }
            SoldiersCollected = 0;
        }
        else if (collider.gameObject.tag.Equals("Rock"))
        {
            if (DeathSound != null)
            {
                Vector3 soundLocation = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + 20.0f, gameObject.transform.position.z);
                AudioSource.PlayClipAtPoint(DeathSound, soundLocation);
            }

            Destroy(gameObject);
        }
    }