Menu
CoddyTech

Recap: Twin Cannon

Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 6 of 64.

This chapter built objects from small components: shared code in a base class, abstract steps each subclass writes, and parts that require each other. The second turret reuses all of it.

challenge icon

Challenge

Easy

Give Turret2 its TwinCannon.

  1. In TwinCannon, make Fire() call Launch twice, with new Vector3(-0.4f, 0f, 1f) and new Vector3(0.4f, 0f, 1f).
  2. In TurretControl, make the field a Weapon and fetch it with GetComponent<Weapon>(), so both turrets work.

Press Play and fire: Turret2 fires two shells per pull. Then Check.

Try it yourself

using UnityEngine;

public class TwinCannon : Weapon
{
    protected override void Fire()
    {
        // two shells for one shell of ammo, 0.4 left and 0.4 right of the spot 1 unit ahead
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Game Architecture in Unity

Practice on your own: Unity playground