Menu
CoddyTech

Recap: Breakable Wall

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

challenge icon

Challenge

Easy

A wall of ten bricks stands in front of a cannon. The ball is the cannonball (tagged Ball, script Cannon.cs, already written): the left and right arrows aim, Space fires. Every brick is a Rigidbody with a Brick script and a breakSpeed (6). Write Brick.cs:

  • When the ball hits a brick at breakSpeed m/s or faster, the brick breaks: log Brick broken and destroy that brick.
  • Nothing else breaks a brick: not a slower ball, and not a brick that lands on the ground or on another brick, however fast it falls.

Press Play and knock the wall down, then Check.

Try it yourself

using UnityEngine;

public class Brick : MonoBehaviour
{
    public float breakSpeed = 6f;
}

All lessons in Physics and Gameplay