Menu
CoddyTech

Coins to Collect

Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 28 of 63.

challenge icon

Challenge

Medium

Now the coins. Every coin already has a trigger collider, and the ball's Rigidbody makes triggers fire. Keep Ball as it is, and add to Coin:

  • An OnTriggerEnter that hides the coin with gameObject.SetActive(false) when the collider that came in has the Player tag. The ball has it.
  • Anything else that rolls into a coin, a crate for example, leaves the coin where it is.

Press Play and collect every coin, then Check.

Try it yourself

using UnityEngine;

public class Coin : MonoBehaviour
{
    // The next lesson makes this coin collectable.
}

All lessons in Physics and Gameplay