Coins to Collect
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 28 of 63.
Challenge
MediumNow 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
OnTriggerEnterthat hides the coin withgameObject.SetActive(false)when the collider that came in has thePlayertag. 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
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable Wall5Project: Coin Rush
The Rolling BallCoins to Collect