Esempio n. 1
0
    //public void OnCollisionEnter2D(Collision2D col){
    public void OnTriggerEnter2D(Collider2D col)
    {
        // get the player controller reference
        CollectableCollector collector = col.GetComponent <CollectableCollector>();

        // if we collided with a gameobject that has a CollectableCollector component
        if (collector != null && collector.itemType == itemType)
        {
            // Debugging
            if (DEBUG_MODE)
            {
                Debug.Log("DEBUG: Collectable Collided with " + col.gameObject.name);
            }

            // Add one coin to the player counter
            collector.CollectItem();

            // Play Collection Sound
            if (collectedSound != null)
            {
                collectedSound.Play();
            }

            // disable the coin
            if (disableWhenCollected)
            {
                gameObject.SetActive(false);
            }

            // call our goal event, ignore this if you don't have any events
            coinCollectedEvent.Invoke();
        }
    }
Esempio n. 2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        CollectableCollector cc = collision.GetComponent <CollectableCollector>();

        if (cc != null)
        {
            if (targetType == cc.itemType && cc.collectedItems >= amountRequired)
            {
                triggeredEvent.Invoke();
            }
            else
            {
                notEnoughEvent.Invoke();
            }
        }
    }