Menu
CoddyTech

Coins to Collect

Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 29 of 71.

challenge icon

Challenge

Medium

Let the ball collect the coins.

  1. In Coin.cs, add void OnTriggerEnter(Collider other).
  2. When other.CompareTag("Player"), hide the coin with gameObject.SetActive(false);. Anything else, like the crate, leaves it.

Press Play and roll into a coin: it disappears. Then Check.

Try it yourself

using UnityEngine;

public class Coin : MonoBehaviour
{
    // Hide the coin when the ball (tag Player) rolls into it
}

All lessons in Physics and Gameplay

Practice on your own: Unity playground