Montag, 13. April 2020

Unity - how to collect item

The item to collect is a prefab.
This prefab got a collider
The collider of the prefab is checked as 'isTrigger'!
The gameobject of this collectable item is tagged as 'Coin'.

The prefab of the player actor checks for collisions in its script:

private void OnTriggerEnter2D(Collider collision)
{
       if (collision.gameObject.CompareTag("Coin"))
       {
                Destroy(collision.gameObject);
                MyPersistentManager.Instance.DoCollectCoinAction(); // todo

        }
}

0 Kommentare:

Kommentar posten

Abonnieren Kommentare zum Post [Atom]

<< Startseite