Ilumisoft Docs
  • Products
  • Bundles
    • Ultimate Asset Bundle
  • Tools
    • Visual State Machine
      • Setup
      • Create your first State Machine
      • Open the Graph Editor
      • Create a State
      • Create a Transition
    • Scene Creator
    • Script Templates
      • Create Script from Template
      • Create a Custom Template
      • Add, Edit or Remove Templates
    • Startup Manager
      • Setup
      • How to Add Systems
      • How It Works
    • Volume Control
      • Setup
      • How to create volume sliders & toggles
      • How to create a volume driven AudioSource
      • How to use the Volume Control API
    • Color Control
    • Graphics Control
      • Getting Started
      • Writing Custom Settings
        • Example 1: Writing the Soft Particles Setting
        • Example 2: Writing the Shadow Setting
    • Game Action System
      • Getting Started
      • Components
        • Game Action Trigger
        • Game Action
        • Game Action Task
      • How To's
        • Creating custom tasks
  • Game Templates
    • Connect
    • Hex
    • Defuse
    • Merge Dice
    • Bubble Pop
    • Downhill Ride
  • Support
    • Help
Powered by GitBook
On this page
  • Example: Log Message Task
  • Example: Wait Until Key Pressed Task

Was this helpful?

  1. Tools
  2. Game Action System
  3. How To's

Creating custom tasks

You can easily write your own tasks. This allows you to create highly customizable tasks that are specific to your game's unique requirements.

Example: Log Message Task

In this example we will write a simple task that will log a message to the console. Create a new Script called LogMessageTask.cs and paste the following content:

using Ilumisoft.GameActionSystem;
using UnityEngine;

/// <summary>
/// Logs the given message when being executed
/// </summary>
[AddComponentMenu("Game Action System/Tasks/Debug/Log Message (Task)")]
public class LogMessageTask : GameActionTask
{
    /// <summary>
    /// A message that can be defined in the inspector
    /// </summary>
    public string message = string.Empty;

    /// <summary>
    /// This will be invoked when the task is executed
    /// </summary>
    /// <returns></returns>
    protected override StatusCode OnExecute()
    {
        // Log the message
        Debug.Log(message);

        // As the task is completed, when return the completed status code
        return StatusCode.Completed;
    }
}

Example: Wait Until Key Pressed Task

You can also write tasks that are running over multile frames before they are completed. The following task will be running until a specific key is pressed. This could be used for example on a sequential Game Action to delay a timeline from being played until the player pressed a key.

using Ilumisoft.GameActionSystem;
using UnityEngine;

/// <summary>
/// When added to a Game Action set to Sequential, this task will block any later task from being executed until the given key is pressed
/// </summary>
[AddComponentMenu("Game Action System/Tasks/Time/Wait Until Key Pressed (Task)")]
public class WaitUntilKeyPressedTask : GameActionTask
{
    /// <summary>
    /// The key that should be waited on
    /// </summary>
    public KeyCode keyCode = KeyCode.Space;

    /// <summary>
    /// This will be invoked when the task is executed
    /// </summary>
    /// <returns></returns>
    protected override StatusCode OnExecute()
    {
        // The task is completed, when the given key is pressed
        if (Input.GetKeyDown(keyCode))
        {
            return StatusCode.Completed;
        }

        // Otherwise the task is still being executed
        return StatusCode.Running;
    }
}
PreviousHow To'sNextConnect

Last updated 2 years ago

Was this helpful?