Source file unity-csharp/arcade-classics/space-invaders/Invader.cs from the GDnD code examples. Download raw file
// GDnD wiki example
// Demonstrates: a single formation member that dies on a hit and reports back to its formation
// Related pages: [[overview-arcade-classics-as-learning-projects]], [[csharp-interfaces]]
using UnityEngine;
// One invader. Like the Breakout brick, it owns almost nothing: it is hit, it
// tells its formation, and it disappears. The formation does the marching and
// the bookkeeping.
public class Invader : MonoBehaviour, IHittable
{
[SerializeField] private int scoreValue = 50;
public int ScoreValue => scoreValue;
private InvaderFormation formation;
public void Bind(InvaderFormation owner)
{
formation = owner;
}
public void Hit()
{
formation?.OnInvaderKilled(this);
}
}