Beispiel #1
0
    // this function is used so that the object tag can add the following commands listed for each object.
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "object")
        {
            ObjectType type = other.GetComponent <ObjectScript> ().type;

            switch (type)
            {
            case ObjectType.Coin:
                scoreGenerator.AddScore(1);
                audioSource.clip = CollectingCoin;
                audioSource.Play();
                break;

            case ObjectType.HealthPack:
                scoreGenerator.AddHealth(1);
                audioSource.clip = CollectingHealthPack;
                audioSource.Play();
                break;

            case ObjectType.OilBarrell:
                scoreGenerator.AddHealth(-1);
                audioSource.clip = CarCrash;
                audioSource.Play();
                Instantiate(explosion, transform.position, Quaternion.identity);
                break;

            case ObjectType.Battery:
                scoreGenerator.Battery(10);
                audioSource.clip = BatterySound;
                audioSource.Play();
                break;
            }

            Destroy(other.transform.parent.gameObject);
        }
    }