Coins to Collect
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 29 of 71.
Challenge
MediumLet the ball collect the coins.
- In
Coin.cs, addvoid OnTriggerEnter(Collider other). - When
other.CompareTag("Player"), hide the coin withgameObject.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
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad4Coroutines
InvokeInvokeRepeating, CancelInvokeYour First CoroutineLoops in CoroutinesStopping CoroutinesRecap: Countdown10Project: Arena Escape
The ArenaHunters2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable Wall5Project: Coin Rush
The Rolling BallCoins to CollectPractice on your own: Unity playground