Skip to content

Combat & Enemies

The Combat & Enemies system lets you configure enemy ships, their weapons, health, movement patterns, and spawn behavior through the Unity Inspector. Enemies automatically scale with wave progression.

What You Can Customize

This guide covers all combat and enemy customization:

  • Enemy weapon properties (bullet speed, damage, fire rate)
  • Enemy health, movement speed, and score rewards
  • Explosion effects when enemies are destroyed
  • Enemy bullet appearance and behavior
  • Available enemies in wave rotations
  • Enemy visual appearance

All customization happens through Inspector fields and prefab management.

Enemy customization in Unity Inspector

Enemy Prefabs

Enemy ships are prefabs containing all enemy-related components.

Location

Assets > Prefabs > Enemies

Each enemy prefab includes:

  • SpriteRenderer: Visual appearance of the enemy ship
  • Enemy: Combat behavior and properties
  • Collider: Collision detection
  • Health Slider: UI element showing enemy health
  • Explosion Prefab: Particle effect reference for destruction

Enemy Weapon Configuration

Configure how enemies attack the player.

Location

Select an enemy prefab, then view the Enemy component in the Inspector.

Inspector Fields

Enemy Weapon:

  • Bullet Prefab: The projectile prefab enemies shoot
  • Bullet Speed: How fast enemy bullets travel
  • Bullet Damage: Damage dealt to player shield on hit
  • Shoot Cooldown: Time between shots (in seconds)

Weapon Behavior

Enemies automatically:

  1. Shoot at regular intervals based on Shoot Cooldown
  2. Aim bullets toward the player’s current position
  3. Fire from their current location
  4. Play shooting sound effect on each shot

Lower Shoot Cooldown values mean faster fire rate.

Enemy Properties

Configure enemy health, movement, and rewards.

Inspector Fields

Enemy Properties:

  • Max Health: Starting health of the enemy
  • Move Speed: How fast the enemy moves
  • Kill Reward: Score awarded when enemy is destroyed

Additional References:

  • Health Slider: UI slider reference showing current health
  • Explosion Prefab: Particle effect played on destruction

Enemy Behavior

Movement:

  • Enemies move in random directions
  • Bounce off screen boundaries
  • Change direction after bouncing
  • Movement is continuous and autonomous

Health System:

  • Health slider appears when enemy takes damage
  • Slider hides after 1 second if enemy survives
  • When health reaches 0, enemy is destroyed

Rewards:

  • Kill Reward score is added to player’s total
  • Score is awarded when enemy dies
  • Different enemies can have different reward values

Wave Scaling

Enemies automatically become stronger with each wave. This happens through the ScaleProperties() method.

Scaling Formula

Health scaling:

Scaled Health = Max Health * (1 + 0.1 * Current Wave)

Damage scaling:

Scaled Damage = Bullet Damage * (1 + 0.1 * Current Wave)

This means:

  • Wave 1: Base stats (100% health, 100% damage)
  • Wave 5: 150% health, 150% damage
  • Wave 10: 200% health, 200% damage

The scaling is automatic and cannot be disabled. To adjust difficulty curve, modify the base stats in the enemy prefabs.

Explosion Effects

Each enemy has a particle effect that plays when destroyed.

Explosion Prefab Location

Assets > Prefabs > Enemies > Explosions

Customizing Explosions

Steps:

  1. Open the explosion prefab for your enemy
  2. Adjust the Particle System properties:
    • Color
    • Size
    • Lifetime
    • Emission rate
    • Velocity
    • Shape

Matching explosions to enemies:

  • Each enemy prefab references its own explosion in the Explosion Prefab field
  • You can create unique explosions for different enemy types
  • Or reuse the same explosion across multiple enemies

Steps to assign explosion:

  1. Select enemy prefab
  2. Locate the Explosion Prefab field in the Enemy component
  3. Drag your explosion prefab into the field

Enemy Bullet Customization

Customize the appearance of enemy projectiles.

Bullet Prefab Location

Assets > Prefabs > Bullets > Enemy Bullets

Changing Enemy Bullet Appearance

Steps:

  1. Open the enemy bullet prefab
  2. Locate the SpriteRenderer component
  3. Replace the sprite with your custom bullet shape
  4. Adjust size, color, and rotation

Assigning Bullets to Enemies

Each enemy can use different bullet prefabs:

  1. Select the enemy prefab
  2. In the Enemy component, locate Bullet Prefab field
  3. Drag your custom bullet prefab into the field

This allows different enemy types to shoot visually distinct projectiles.

Managing Available Enemies

Control which enemies spawn during waves through the WaveManager component.

Location

Game Scene > === GAME MANAGER === > WaveManager

The WaveManager contains an Enemy Prefabs array that determines which enemies can spawn.

Inspector Fields

Enemy Prefabs Array:

  • Array of enemy prefabs available for spawning
  • Enemies are randomly selected from this array during waves
  • Add/remove enemies by modifying this array

Adding New Enemies to Wave Pool

Steps:

  1. Navigate to Game Scene > === GAME MANAGER ===
  2. Select the GameObject with the WaveManager component
  3. In the Inspector, locate the WaveManager component
  4. Expand the Enemy Prefabs array
  5. Increase the array size
  6. Drag your new enemy prefab into the new slot

The enemy will now spawn during waves.

Removing Enemies from Wave Pool

Steps:

  1. Navigate to the WaveManager component
  2. Expand the Enemy Prefabs array
  3. Find the enemy you want to remove
  4. Either:
    • Remove the element from the array, OR
    • Decrease the array size to exclude it

The enemy will no longer spawn during waves.

Creating Enemy Variants

Create multiple enemy types with different behaviors and stats.

Steps to Create New Enemy Type

  1. Duplicate existing prefab:

    • Navigate to Assets > Prefabs > Enemies
    • Right-click an enemy prefab → Duplicate
    • Rename it (e.g., “Enemy_Fast”)
  2. Customize stats:

    • Open the prefab
    • Adjust Enemy component weapon properties
    • Modify health and movement values
    • Change kill reward
  3. Customize visuals:

    • Replace the SpriteRenderer sprite
    • Assign custom bullet prefab
    • Create/assign unique explosion effect
  4. Add to wave pool:

    • Open Game Scene
    • Navigate to === GAME MANAGER === > WaveManager
    • Add the new prefab to the Enemy Prefabs array

The new enemy type will now appear in wave rotations.

Enemy Visual Customization

Change enemy ship appearance by swapping sprites.

Changing Enemy Sprite

Steps:

  1. Navigate to Assets > Prefabs > Enemies
  2. Select the enemy prefab you want to customize
  3. Locate the SpriteRenderer component
  4. Import your custom enemy sprite
  5. Set the sprite’s Texture Type to “Sprite (2D and UI)“
  6. Drag your sprite into the Sprite field of the SpriteRenderer

The enemy’s visual appearance updates immediately.

Adjusting Collider

When changing sprite shape, you may need to adjust the collider:

Steps:

  1. Select the enemy prefab
  2. Locate the Collider2D component
  3. Adjust collider size/shape to match new sprite
  4. For complex shapes, use Polygon Collider 2D

Proper collider setup ensures accurate collision detection.

Health Slider Configuration

The health slider shows enemy damage visually during combat.

Inspector Fields

Health Slider Reference:

  • Health Slider: UI Slider component reference

Behavior

  • Slider is hidden by default
  • Appears when enemy takes damage
  • Updates to show current health percentage
  • Hides after 1 second if enemy survives

The slider is automatically managed by the Enemy script.

Understanding Enemy AI

Enemy movement is autonomous and random:

  1. Initialization: Enemy starts with random direction
  2. Movement: Moves continuously in current direction
  3. Boundary Detection: Checks if position is within camera bounds
  4. Bounce: Reflects direction when hitting boundary
  5. New Direction: Sets new random direction after bounce
  6. Repeat: Continues moving in new direction

This creates unpredictable movement patterns that challenge the player.

Weapon Behavior Details

Enemy shooting behavior:

  1. Coroutine Start: ShootRoutine begins when enemy spawns
  2. Interval Wait: Waits for Shoot Cooldown duration
  3. Target Calculation: Gets direction to player’s current position
  4. Bullet Spawn: Instantiates bullet at enemy position
  5. Bullet Properties: Sets speed, damage, and ownership
  6. Repeat: Returns to step 2

Enemies always aim at the player’s position when firing, not where the player will be.

Getting Help

Don’t hesitate to reach out if you need help:

  • Email: [email protected]
  • Social: Find me on GitHub, Twitter, or any of the platforms linked in the header

I built these tools to help developers, so please use me as a resource. Questions, bug reports, feature requests—I want to hear all of it.


Next: Configure Wave System to adjust wave progression and spawning.