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
EasyGive Turret2 its TwinCannon.
- In
TwinCannon, makeFire()callLaunchtwice, withnew Vector3(-0.4f, 0f, 1f)andnew Vector3(0.4f, 0f, 1f). - In
TurretControl, make the field aWeaponand fetch it withGetComponent<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
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Game Architecture in Unity
1Components, Not Hierarchies
Small ComponentsA Base Enemy ScriptAbstract ComponentsComponents Working TogetherRecap: Modular TurretRecap: Twin Cannon4Serialized Data
Serializable ClassesLists in the InspectorEnums in the InspectorRecap: Loot TableRecap: Roll the Loot2Interfaces in Unity
IDamageableInterfaces and TryGetComponentGetComponentsRecap: Interact KeyRecap: Nearest in ReachPractice on your own: Unity playground