Makinom - Game Toolkit for Unity
  • Features
  • Showcase
  • Guide
    • Documentation
    • Tutorials
    • Extensions
    • API
  • Makinom 1
    • Tutorials
    • Plugins
    • API
  • Support
  • Forum
  • Get Makinom

Guide

Schematics

  • Setting the Player
  • Simple Character Controller
  • Mouse Orbit Camera
  • Random Waypoints

Breakout

  • Breakout Tutorial Introduction
  • 01 First Steps
  • 02 Player Controls
  • 03 Bricks
  • 04 Losing a Life
  • 05 UI Setup
  • 06 Sound Assignments

Space Shooter

  • Space Shooter Tutorial Introduction
  • 01 First Steps
  • 02 Player Move Controls
  • 03 Player Weapon Controls
  • 04 Hit and Destroy
  • 05 Asteroids
  • 06 Game Controller
  • 07 UI Setup
  • 08 Player’s Destruction
  • 09 Enemy Ship Mechanics
  • 10 Enemy Ship
  • 11 Moving the Background

Match 3

  • Match 3 Tutorial Introduction
  • 01 First Steps
  • 02 UI Setup
  • 03 Generating the Level
  • 04 Matching Jewels
  • 05 Destroying Jewels
  • 06 Game Controls
  • 07 Jewel Setup

Survival Shooter

  • Survival Shooter Tutorial Introduction
  • 01 First Steps
  • 02 Player Movement
  • 03 Player Shooting
  • 04 Enemy Mechanics
  • 05 Setting up the Enemies
  • 06 UI Setup
  • 07 Player’s Death
  • 08 Enemy Spawner

2D Roguelike

  • 2D Roguelike Tutorial Introduction
  • 01 First Steps
  • 02 Generating the Level
  • 03 Level Generation Machines
  • 04 Player Controls
  • 05 Walls, Food and Exit
  • 06 Game Manager and UI Setup
  • 07 Enemy Mechanics
  • 08 Game Over

2D Platformer

  • 2D Platformer Tutorial Introduction
  • 01 First Steps
  • 02 Player Movement
  • 03 Camera and Background
  • 04 Shooting Rockets
  • 05 Enemy Mechanics
  • 06 Setting up the Enemies
  • 07 Enemy Spawners
  • 08 Player Damage and Fall Remover
  • 09 Health Pickup
  • 10 Bomb Pickup
  • 11 Bomb Prefabs and Lay Bombs
  • 12 Pickup Spawner
  • 13 UI Setup
  • 14 Background Animations
  • Home
  • Guide
  • Tutorials
  • Space Shooter
  • 06 Game Controller

06 Game Controller

Table of Contents
  • Game Controller: Schematic
    • Settings
      • Machine Start Variables
      • Prefabs
    • Float Random
      • Variable Settings
      • Minimum Value
      • Maximum Value
    • Spawn Prefab
      • Position
    • Is Schematic Stopped
    • Loop
      • Variable Settings (Counter)
    • Wait
    • Wait
  • Game Controller: Auto Machine
    • Start Settings
    • Machine Execution Settings
    • Local Start Variables
  • Testing

Setting up the game controller spawning the enemy waves.

The game controller is responsible for spawning the enemy waves. For now, we’ll only use the 3 asteroids as enemies – enemy ships will be added later. The game controller will run in a repeating auto machine component and use Wait nodes to wait between spawning enemies and waves.

Game Controller: Schematic #

Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.

Settings #

We’ll set up local variables as Machine Start Variables for easy setup in the machine component at a later time. When using the schematic in a machine component, the defined start variables will be added automatically, using their default values.

Machine Start Variables #

Click on Add Start Variable to add a local start variable that will be exposed to the machine component’s inspector.

  • Variable Key
    Set to spawnPosition.
  • Type
    Select Vector3.
  • Default Value
    Set to X=6, Y=0, Z=16.

Again, click on Add Start Variable to add another local start variable.

  • Variable Key
    Set to hazardCount.
  • Type
    Select Int.
  • Default Value
    Set to 10.

Prefabs #

We’ll add the asteroid prefabs as a single prefab resource to randomly spawn one of them. Click on Add Prefab Resource to add a prefab resource. Make sure that Destroy Prefabs is disabled.

  • Name
    Set to Hazards.
  • Use Order
    Select Random.

Change the first prefab’s settings.

  • Prefab
    Select Asteroid 1.
    Can be found at Assets/Tutorial Resources/Prefabs/.
  • Use Pooling
    Enable this setting.

Click on Add Prefab to add another prefab to the resource.

  • Prefab
    Select Asteroid 2.
    Can be found at Assets/Tutorial Resources/Prefabs/.
  • Use Pooling
    Enable this setting.

Click on Add Prefab to add another prefab to the resource.

  • Prefab
    Select Asteroid 3.
    Can be found at Assets/Tutorial Resources/Prefabs/.
  • Use Pooling
    Enable this setting.

Float Random #

Add Node > Value > Float > Float Random

This node will store a random float value into a variable. We’ll use it to create a random X-position for the spawning enemy.

Variable Settings #

  • Variable Key
    Set to xPos.
  • Variable Origin
    Select Local.
  • Operator
    Select Set.

Minimum Value #

  • Minimum Value
    Select Variable > Vector3 Variable and X.
  • Variable Key
    Set to spawnPosition.
  • Variable Origin
    Select Local.
  • Math Function
    Select Negate.

Maximum Value #

  • Maximum Value
    Select Variable > Vector3 Variable and X.
  • Variable Key
    Set to spawnPosition.
  • Variable Origin
    Select Local.
  • Math Function
    Select None.

Spawn Prefab #

Add Node > Game Object > Prefab > Spawn Prefab

We’ll spawn a prefab using the random X position we just created.

  • Prefab
    Select Prefab 0: Hazards.
  • Target Type
    Select Position.

Position #

  • Vector3 Type
    Select Value > Set Axis.

The X position will use the random float value we created.

  • X-Axis
    Select Variable > Float Variable.
  • Variable Key
    Set to xPos.
  • Variable Origin
    Select Local.

The Y position will use the Y position of the local start variable spawnPosition.

  • Y-Axis
    Select Variable > Vector3 Variable and Y.
  • Variable Key
    Set to spawnPosition.
  • Variable Origin
    Select Local.

The Y position will use the Z position of the local start variable spawnPosition.

  • Z-Axis
    Select Variable > Vector3 Variable and Z.
  • Variable Key
    Set to spawnPosition.
  • Variable Origin
    Select Local.

Is Schematic Stopped #

Add Node > Machine > Is Schematic Stopped

This node checks if the schematic is stopped, e.g. due to the machine object being destroyed. We’ll use it to prevent looping through the enemy spawns when the level is reloaded after game over.

There are no additional settings.

Loop #

Add Node > Base > Loop

The Loop node is a useful node to repeat a part of your schematic for a number of times. In short, it’ll increase a counter variable (int) by 1 each time it’s used until it reaches a defined maximum value.

This node is connected to the Running slot of the Is Schematic Stopped node.

  • Max Count
    Select Variable > Int Variable.
  • Variable Key
    Set to hazardCount.
  • Variable Origin
    Select Local.

Variable Settings (Counter) #

  • Reset
    Enable this setting.
  • Variable Key
    Set to count.
  • Variable Origin
    Select Local.

Wait #

Add Node > Base > Wait

This node will wait for a defined amount of time. We’ll wait for a random time between 0.5 and 1 seconds before spawning the next enemy.

This node is connected to the Loop slot of the Loop node and connects back to the Float Random node. This will repeat spawning a prefab as long as the count hasn’t reached the required number.

  • Random
    Enable this setting.
  • Time (s)
    Set to 0.5 (Value).
  • Time 2 (s)
    Set to 1 (Value).

Wait #

Add Node > Base > Wait

We’ll wait for a random time between 2 and 5 seconds until the schematic ends (which will restart the machine, spawning the next wave).

This node is connected to the Finished slot of the Loop node.

  • Random
    Enable this setting.
  • Time (s)
    Set to 2 (Value).
  • Time 2 (s)
    Set to 5 (Value).

And that’s it for the schematic – click on Save Schematic and save it as GameController in Assets/Schematics/.

Game Controller: Auto Machine #

Now, we’ll add the Game Controller schematic to the scene. Create a new empty object (e.g. using the Unity menu: GameObject > Create Empty), rename it to Game Controller and place it at X=-10, Y=0, Z=2.

Add an auto machine component to the game object (e.g. using the component menu: Makinom > Machines > Auto Machine) and change the following settings.

Start Settings #

  • Start
    Enable this setting.
  • Start Delay (s)
    Set to 1.
  • Repeat Execution
    Enable this setting.
    The machine will retry executing after it ended.

Machine Execution Settings #

  • Schematic Asset
    Select GameController.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.

Local Start Variables #

The Machine Start Variables we’ve set up in the schematic are automatically added here with their default values – since the default values are already what we need, we don’t have more to do here. Make sure all variables are enabled.

And that’s it for now – don’t forget to save the scene.

Testing #

Click on Play to test the game. Now, the game controller will spawn waves of 10 asteroids (spawning randomly one of the 3 asteroids) and you’ll be able to destroy them by firing bolts on them. When the player is hit, the game will just keep running with the player being gone – we’ll take care of this later.

The next tutorial will handle the UI setup.

Share This Article :
  • Facebook
  • Twitter
  • LinkedIn
  • Pinterest
Updated on December 17, 2020
Table of Contents
  • Game Controller: Schematic
    • Settings
      • Machine Start Variables
      • Prefabs
    • Float Random
      • Variable Settings
      • Minimum Value
      • Maximum Value
    • Spawn Prefab
      • Position
    • Is Schematic Stopped
    • Loop
      • Variable Settings (Counter)
    • Wait
    • Wait
  • Game Controller: Auto Machine
    • Start Settings
    • Machine Execution Settings
    • Local Start Variables
  • Testing
Sitemap
  • Features
  • Showcase
  • Guide
    • Documentation
    • Tutorials
    • Extensions
    • API
  • Makinom 1 Hub
    • Tutorials
    • Plugins
    • API
  • Support
  • Forum
  • Get Makinom
  • Contact
  • Blog
  • ORK Framework
  • gamingislove.com
Categories
  • Makinom 1 (97)
    • Tutorial (97)
      • 2D Platformer (14)
      • 2D Roguelike (8)
      • Breakout (6)
      • How-to (34)
      • Match 3 (6)
      • Schematic (4)
      • Scripting (6)
      • Space Shooter (11)
      • Survival Shooter (8)
  • News (11)
  • Release (67)
Search

© 2015 Gaming is Love e.U.

Disclosure: This site may contain affiliate links, which means I may receive a commission if you click a link and purchase something that I have recommended. While clicking these links won’t cost you any money, they will help me fund my development projects while recommending great assets!