Menu
CoddyTech

Into the Cup

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

challenge icon

Challenge

Hard

Let a slow marble drop into the cup.

  1. In Hole, add void OnTriggerEnter(Collider other).
  2. When other.TryGetComponent(out Golf golf) and other.attachedRigidbody.linearVelocity.magnitude < sinkSpeed, log "In the cup in " + golf.strokes + " strokes!" and call other.gameObject.SetActive(false);.

Press Play and sink the marble: a fast one rolls over the cup. Then Check.

Try it yourself

using UnityEngine;

public class Hole : MonoBehaviour
{
    [SerializeField] private float sinkSpeed = 3f;

    // a slow marble drops into the cup, a fast one rolls over
}

All lessons in Physics and Gameplay

Practice on your own: Unity playground