Saturday, March 28, 2015

Unity: Two flavours of LERP





 In this post I will show two uses of LERP as you can often see in Unity scripts.


LERP


 LERP stands for linear interpolation and it is easy way how to get "mid-points" if you need to travel from point A to point B. Let's say you need to get from point A to point B in 3 seconds. We will call these 3 seconds as "MOVEMENT_TIME". You set up some counter "_currentTime" that will increase every frame with elapsed time until you reach MOVEMENT_TIME. Your current position on every frame is then calculated like this:

newPosition = point A + (point B - point A) * (_curerntTime / MOVEMENT_TIME)

 What it does is:
  • elapsed time is changed into range 0 to 1 (_curerntTime / MOVEMENT_TIME),
  • distance between ending and starting point (point B - point A) is calculated,
  • these two values are multiplied to know how much of the distance we already traveled (if time is 0 we are still in beginning and if time is 1 we are in target position),
  • finally we add the distance to starting position (point A) to get current position
 As this is used very frequently Unity has Lerp function in its Mathf class. It simplifies whole thing to single call to:

float newValue = Mathf.Lerp(valueA, valueB, time);

 But points are not single values! Fortunately, Unity has whole bunch of Lerp functions for Vector2, Vector3, Color, ... Our position change would look like this in code:

Vector2 newPosition = Vector2.Lerp(PointA, PointB, _currentTime / MOVEMENT_TIME);



Two common usages of LERP


 Now look at following picture:

 Both, ship and zeppelin are using LERP for its movement. But, it is obvious that zeppelin is not moving linearly.

 The ship is using our previous formula: we have starting point, end point and every frame we are looking for current point between them. Here is chart with our x position with regard to time:


 Here is complete code for ship:

using UnityEngine;
using System.Collections;

public class Ship : MonoBehaviour {

    public const float MOVEMENT_TIME = 3f;

    private float _startX;
    private float _endX;
    private float _currentTime;

    void Start() {
        _startX = -1f;
        _endX = 1f;
        _currentTime = 0;
    }

    void Update() {
        // update time
        _currentTime = Mathf.Min(_currentTime + Time.deltaTime, MOVEMENT_TIME);

        // update position
        Vector3 newPosition = transform.position;
        newPosition.x = Mathf.Lerp(_startX, _endX, _currentTime / MOVEMENT_TIME);
        transform.position = newPosition;

        // check if already in destination
        if (_currentTime >= MOVEMENT_TIME) {
            // move again, but switch start and destination
            float tmpX = _startX;
            _startX = _endX;
            _endX = tmpX;

            // init timer again
            _currentTime = 0;

            // turn ship to head in right direction
            Vector3 newScale = transform.localScale;
            newScale.x *= -1;
            transform.localScale = newScale;
        }
    }
}


 Zeppelin is moving also using LERP, but instead of interpolating between start and end position, it is interpolating between current and end position. It also does not calculate time between 0 and 1. Instead it uses fixed value. This fixed value says how much of the remaining distance (from current position to target position) should be traveled. As the remaining distance is getting shorter and shorter then also the calculated distance to move in every frame is shorter and shorter, so the zeppelin is slowing down. Exactly, it does never reach target position, but it gets so close to it that this is not problem for us. The chart for movement looks like this:


 And here is complete code for zeppelin:

using UnityEngine;
using System.Collections;

public class Zeppelin : MonoBehaviour {

    public const float MOVEMENT_TIME = 3f;

    private float _endX;

    void Start() {
        _endX = 1f;
        StartCoroutine(InfiniteSwap());
    }

    void Update() {
        // update position
        Vector3 newPosition = transform.position;
        newPosition.x = Mathf.Lerp(transform.position.x, _endX, MOVEMENT_TIME * 0.5f * Time.deltaTime);
        transform.position = newPosition;
    }

    IEnumerator InfiniteSwap() {
        while (true) {
            // suspend for 3 seconds
            yield return new WaitForSeconds(MOVEMENT_TIME);

            // change end position
            _endX *= -1;

            // turn zeppelin to head in right direction
            Vector3 newScale = transform.localScale;
            newScale.x *= -1;
            transform.localScale = newScale;
        }
    }
}

 We are using coroutine here to change target position every 3 seconds. In both cases we are moving form -1 to 1 in x direction.

 The second way of using Lerp has lot of usages. For example if you want your camera move from player to focus on some object, it looks much better if you do it in this way. In Unity example projects you can see this for camera movement in Survival shooter or for alarm lights intensity in Stealth project.



Friday, March 6, 2015

Mobile Income Report #7 - January & February 2015





previous parts
  Mobile Income Report #7 - December 2014
  Mobile Income Report #6 - November 2014
  Mobile Income Report #5 - October 2014 
  Mobile Income Report #4 - September 2014 
  Mobile Income Report #3 - August 2014
  Mobile Income Report #2 - July 2014
  Mobile Income Report #1 - June 2014
  Apps page - Portfolio (what are my assets?)


 If you do not want to miss any of my Income Reports you can follow me on Twitter. Just click the button above.

 Under Apps page you can see my portfolio. It is list of the games that are then reported in Income Reports. The portfolio is regularly updated with new information (releases for new platforms, new updates, ...)



 As there were no interesting events in January I merged January and February report together.

What I did in January and February

  • Flat Jewels Match 3 is finished. In February we released iOS version at iTunes. Unfortunately, number of downloads is low. As we passed Amazon's developer select program with Android version we will have advertising campaign with 500k impressions in March for free,
  • on 27th January Shards was promoted by AppGratis on Android. We finally crossed 50k downloads at Google Play,
  • in the end of February we finished our first HTML5 game Annihilate. You can play it right here. Game is build with Phaser engine. Now we are looking for sponsors. Read whole post on Annihilate here. Annihilate is simple puzzle game in modern design. It scales well on almost any resolution:



Report

 

 First numbers for January. Here are paid apps:

 In January Shards dominates. In the beginning of the month there was positive effect of promotion of iOS version by AppGratis which took place on 31th December 2014 and promotion of Android version on 27th January.

 Here are versions supported with ads for January:

 In January income from ads was really poor. Chartboost was only $39 compared to $61 in December, but it still stays the most profitable ads network for us. Admob earnings are getting lower and lower with the same traffic. In the end of January Flat Jewels Match 3 was released for Android and you can see first $2 from it :-)


 In February paid apps did like this:

 Decrease compared to January (from $76 to $37,5). Almost all earnings are from Shards for Android and iOS.

 Fortunately, income from free versions increased little (from $84,2 to $128,5) to compensate decrease from paid apps:

 Surprise for us are earnings from Chartboost for Flat Jewels Match 3. Despite lower number of downloads compared to Shards, the earnings are almost the same. Now the question is: did we something wrong with Shards? Or did we something good with Flat Jewels Match 3? Flat Jewels Match 3 is also our first free app for iOS.

 Total income for January was $76,0 + $84,2 = $160,2 which is +3,9% increase compared to December.

 Total income for February was $37,5 + $128,5 = $166,0 which is another +3,6% increase compared to January... All I need now is to increase the base for calculation :-)



Next

 

 Next month I will report our experience with looking for sponsors for our first HTML5 game Annihilate. We are working on next HTML5 game.
 Also I invested some money into tutorials by 3DBuzz on new Unity UI. These tutorials are really great and I hope it will help me to start our first own Unity game. We already have clear idea and game design.






Sunday, March 1, 2015

Annihilate, puzzle game made with Phaser engine, is finshed!


 Finally, we just finshed our HTML5 game called Annihilate. Game was made using great Phaser engine. Annihilate is puzzle game in which you are matching pairs o atoms. In 48 levels you have to avoid various pitfalls like lasers, black holes, ...

 Now, we are looking for sponsors. If you are interested, conntact me at my gmail address: tomas[dot]rychnovsky[at]gmail[dot]com

 Game features:
  • 48 puzzle levels,
  • nice simple and clear graphics and music,
  • scales well for different screen resolutions (no black belts on iPhone nor iPad),
  • ready for easy translation



 And you can try the game right here!:



 Screenshots:







Tuesday, February 10, 2015

Phaser tutorial: How to wrap bitmap text

 In past month I started exploring world of HTML5 and Javascript games. Finally I ended with Phaser game engine by Photonstorm and Typescript (in Visual Studio 2013).

 During making our first games I was really missing ability to wrap bitmap text. So, I created helper class TextWraper, that is doing text wrap for me.

 Why you need such a class? You can choose between bitmap and true type fonts. While true type fonts are more flexible, bitmap fonts are more visually appaeling. Unfortunately, Phaser's bitmapText cannot wrap text. If you tune your text screen with "hard coded" new lines and then you change few words or translate it into different language, you have to tune it again...
 
 The final TextWrapper helper not only can wrap the text, but it also splits it into multiple pages returning string[], where every single element is one page of text. You just tell to it what is requested width and height of your text area.

 In example below you can see the TextWrapper class in action (press buttons to change screens). All original new line characters are preserved and other that are needed to wrap long paragraphs are added. Font for the demo was created in Littera.



 Using the class is as simple as this:

        var text: string = 'WRAPPED BITMAP TEXT\n' +
            '-------------------------------------------\n\n' +
            ' This example demonstrates TextWrapper helper class for Phaser game engine, that allows you to easily wrap bitmap text.\n' +
            ' Not only it can wrap long paragraphs into lines but it also splits whole text into multiple pages - ' +
            'touch buttons bellow to go to next or previous page.\n' +
            ' The TextWrapper preserves all original new line characters and ads others, that are necessary to wrap text correctly. ' +
            'After calling wrapText() method string array is returned where each array element is single text page with all necessary new line characters.\n\n' +
            ' By the way, if you like background image it is from our game Shards - the brickbreaker. ' +
            'It is available for Android as well as for iOS. Give it a try! Not a bad way how to create long text and make publicity to our game at once :-)';

        var pages: string[] = Helper.TextWrapper.wrapText(text, 520, 260, 'Font', 25);
        var currentPage: number = 0;
        var bitmapText = this.add.bitmapText(60, 30, 'Font', pages[currentPage], 25);

 As can be seen from the code, the class takes these parameters:
  • text - text to wrap,
  • width - width of target text area,
  • height - height of target text area,
  • fontName - name of the font,
  • size (optional) - to calculate font scale. If omitted then scale = 1;

 The TextWrapper class itself is rather long as it has to handle lot of wrapping issues. For example, it is splitting by words, but in case some word is too wide and would not fit into requested width then this word has to be split in the middle.

 Whole listing for the TextWrapper class is here:

module Helper {
    enum eCharType {
        UNDEFINED = -1,
        SPACE = 1,
        NEWLINE = 2,
        CHARACTER = 3,
        //SPECIAL = 4 // for future
    }

    export class TextWrapper {
        static mText: string;
        static mTextPosition: number;
        static mFontData: any;

        // -------------------------------------------------------------------------
        private static hasNext(): boolean {
            return TextWrapper.mTextPosition < TextWrapper.mText.length;
        }

        // -------------------------------------------------------------------------
        private static getChar(): string {
            return TextWrapper.mText.charAt(TextWrapper.mTextPosition++);
        }

        // -------------------------------------------------------------------------
        private static peekChar(): string {
            return TextWrapper.mText.charAt(TextWrapper.mTextPosition);
        }

        // -------------------------------------------------------------------------
        private static getPosition(): number {
            return TextWrapper.mTextPosition;
        }

        // -------------------------------------------------------------------------
        private static setPosition(aPosition: number): void {
            TextWrapper.mTextPosition = aPosition;
        }

        // -------------------------------------------------------------------------
        private static getCharAdvance(aCharCode: number, aPrevCharCode: number): number {
            var charData = TextWrapper.mFontData.chars[aCharCode];
            
            // width
            var advance: number = charData.xAdvance;
            
            // kerning
            if (aPrevCharCode > 0 && charData.kerning[aPrevCharCode])
                advance += charData.kerning[aPrevCharCode];

            return advance;
        }

        // -------------------------------------------------------------------------
        private static getCharType(aChar: string): eCharType {
            if (aChar === ' ')
                return eCharType.SPACE;
            else if (/(?:\r\n|\r|\n)/.test(aChar))
                return eCharType.NEWLINE;
            else
                return eCharType.CHARACTER;
        }

        // -------------------------------------------------------------------------
        static wrapText(aText: string, aWidth: number, aHeight:number, aFontName: string, aSize? : number): string[] {
            // set vars for text processing
            TextWrapper.mText = aText;
            TextWrapper.setPosition(0);
            // font data
            TextWrapper.mFontData = PIXI.BitmapText.fonts[aFontName];

            // if size not defined then take default size
            if (aSize === undefined)
                aSize = TextWrapper.mFontData.size;

            var scale: number = aSize / TextWrapper.mFontData.size;
            // height of line scaled
            var lineHeight: number = TextWrapper.mFontData.lineHeight * scale;
            // instead of scaling every single character we will scale line in opposite direction
            var lineWidth: number = aWidth / scale;

            // result
            var mLineStart: number[] = [];
            var mLineChars: number[] = [];
            var mPageStart: number[] = [];
            var mMaxLine: number = 0;
            var firstLineOnPage: boolean = true;
            var pageCounter: number = 0;

            // char position in text
            var currentPosition: number = 0;
            // first line position
            mLineStart[mMaxLine] = currentPosition;
            // first page
            mPageStart[pageCounter++] = 0;
            // remaining height of current page
            var remainingHeight: number = aHeight;

            
            // whole text
            while (TextWrapper.hasNext()) {
                var charCount: number = 0;
                // saves number of chars before last space
                var saveSpaceCharCount:number = 0;
                var saveCharPosition:number = -1;
                // (previous) type of character
                var type: eCharType = eCharType.UNDEFINED;
                var previousType: eCharType = eCharType.UNDEFINED;
                // remaining width will decrease with words read
                var remainingWidth: number = lineWidth;
                // previous char code
                var prevCharCode: number = -1;

                // single line
                while (TextWrapper.hasNext()) {
                    currentPosition = TextWrapper.getPosition();
                    // read char and move in text by 1 character forward
                    var char: string = TextWrapper.getChar();
                    // get type and code
                    type = TextWrapper.getCharType(char);
                    var charCode: number = char.charCodeAt(0);

                    // process based on type
                    if (type === eCharType.SPACE) {
                        if (previousType != eCharType.SPACE)
                            saveSpaceCharCount = charCount;

                        ++charCount;
                        remainingWidth -= TextWrapper.getCharAdvance(charCode, prevCharCode);
                    }
                    else if (type === eCharType.CHARACTER) {
                        if (previousType !== eCharType.CHARACTER)
                            saveCharPosition = currentPosition;

                        remainingWidth -= TextWrapper.getCharAdvance(charCode, prevCharCode);

                        if (remainingWidth < 0)
                            break;

                        ++charCount;
                    }
                    else if (type === eCharType.NEWLINE) {
                        var breakLoop: boolean = false;

                         // if there is no more text then ignore new line
                        if (TextWrapper.hasNext()) {
                            breakLoop = true;
                            saveSpaceCharCount = charCount;
                            saveCharPosition = TextWrapper.getPosition();
                            currentPosition = saveCharPosition;
                            // simulate normal width overflow
                            remainingWidth = -1;
                            type = eCharType.CHARACTER;
                        }

                        if (breakLoop)
                            break;
                    }

                    previousType = type;
                    prevCharCode = charCode;
                }


                // lines / pages
                remainingHeight -= lineHeight;
                // set new page if not enough remaining height
                if (remainingHeight < 0)
                    mPageStart[pageCounter++] = mMaxLine;

                if (remainingWidth < 0 && type === eCharType.CHARACTER) {
                    if (saveSpaceCharCount != 0)
                        mLineChars[mMaxLine] = saveSpaceCharCount;
                    else // for too long words that do not fit into one line (and Chinese texts)
                        mLineChars[mMaxLine] = charCount;

                    // does new line still fits into current page?
                    firstLineOnPage = false;

                    // set new page
                    if (remainingHeight < 0) {
                        firstLineOnPage = true;
                        remainingHeight = aHeight - lineHeight;
                    }

                    if (saveSpaceCharCount != 0) {
                        mLineStart[++mMaxLine] = saveCharPosition;
                        TextWrapper.setPosition(saveCharPosition);
                    } else {
                        mLineStart[++mMaxLine] = currentPosition;
                        TextWrapper.setPosition(currentPosition);
                    }
                } else if (!TextWrapper.hasNext()) {
                    if (type === eCharType.CHARACTER) {
                        mLineChars[mMaxLine] = charCount;
                    } else if (type === eCharType.SPACE) {
                        mLineChars[mMaxLine] = saveSpaceCharCount;
                    }
                }
            }

            mPageStart[pageCounter] = mMaxLine + 1;


            // lines into string[]
            var result: string[] = [];

            for (var i = 1; i <= pageCounter; i++) {
                var firstLine: number = mPageStart[i - 1];
                var lastLine: number = mPageStart[i];

                var pageText: string[] = [];
                for (var l = firstLine; l < lastLine; l++) {
                    pageText.push(TextWrapper.mText.substr(mLineStart[l], mLineChars[l]));
                }

                result.push(pageText.join("\n"));
            }

            return result;
        }
    }
}

 You can download the example with Typescript source files here.

 By the way, in last days we released our new mobile game "Flat Jewels Match 3" for iOS and Android - give it try!





Friday, January 30, 2015

Mobile Income Report #7 - December 2014 (monthly income report from Android, iOS, Tizen, ... games)





previous parts
  Mobile Income Report #6 - November 2014
  Mobile Income Report #5 - October 2014

  Mobile Income Report #4 - September 2014 
  Mobile Income Report #3 - August 2014
  Mobile Income Report #2 - July 2014
  Mobile Income Report #1 - June 2014
  Apps page - Portfolio (what are my assets?)


 If you do not want to miss any of my Income Reports you can follow me on Twitter. Just click the button above.

 Under Apps page you can see my portfolio. It is list of the games that are then reported in Income Reports. The portfolio is regularly updated with new information (releases for new platforms, new updates, ...)


What I did in December

  • in December I continued work on our games, mainly Flat Jewels Match 3. We finished the game itself and mainly worked on additional features like various "game services" and so on. Now, when writing this post, the game is released on Android (at Google Play and at Amazon) and it is in approval process for iOS 
Flat Jewels Match 3 - menuFlat Jewels Match 3 - gameplay

  • I also started learning HTML5 and Javascript as it is whole new field of opportunities for simple games. First I used Netbeans IDE, which I really like, for my first attempts. But then I found there is Typescript language that can help with type checks and you can write code in more convenient way, so I switched to Microsoft Visual Studio Community 2013, which is free for individual developers and has Typescript support. Typescript is superset of Javascript, so everything you write is compiled into Javascript,
  • you can start to write your HTML5 game from scratch or save some time and use some engine. There is lot of them. But finally I ended with Phaser by PhotonStorm as I like their approach and it is obvious that the engine is constantly being improved,
  • On 31st December there was promotion event on Shards by AppGratis. It brought more than 17k downloads in one day and more importantly it helped us to gain some positive user ratings.

Report

 Here are December figures for paid apps:


 While income from iOS games is more or less stable (from $27 in November to $24,3), there is decrease in Android versions (from $38,1 to $22,4). Total amount $46,7 means decrease from $65,1 in November.


 Shards with 60% share is still most profitable from our games.

 Stats for free versions of our games are these:


 There is really big decrease from $220,7 in November to $107,4 in December. In November there was good result with Chartboost (close to $150), but it did not lasted long time. Also income from other networks was lower in december.


 Total income for December was $46,7 + $107,4 = $154,1 which is -46% decrease compared to November and it is really very bad result...


Next?

 In January I am continuing in work on our games - Flat Jewels Match 3 game was released on Android and is in approvel process on iOS. I hope it will help me little bit. I am also continuing in my Typescript / Phaser experiments and I hope there will be some results soon.
 

Thursday, December 11, 2014

Mobile Income Report #6 - November 2014 (monthly income report from Android, iOS, Tizen, ... games)





previous parts
  Mobile Income Report #5 - October 2014

  Mobile Income Report #4 - September 2014 
  Mobile Income Report #3 - August 2014
  Mobile Income Report #2 - July 2014
  Mobile Income Report #1 - June 2014
  Apps page - Portfolio (what are my assets?)


 If you do not want to miss any of my Income Reports you can follow me on Twitter. Just click the button above.

 Under Apps page you can see my portfolio. It is list of the games that are then reported in Income Reports. The portfolio is regularly updated with new information (releases for new platforms, new updates, ...)


What I did in November

  •  in November there were several promotion events for our previous games. All of them were in this way: we will promote your app, but you will set it free during promotion period. So, there is not direct impact into income, but it is still worth as it brings some publicity. The events were these:
    • 7th November - Fruit Dating was featured as "Free app of the day" at Amazon Brazil. It brought 854 downloads. It is obvious, that Amazon in US, UK or Germany is more popular (as we experienced with Shards promotion) than in Brazil, but it is still great feeling if your game is featured somewhere,
    • 11th-14th November - Shards was featured at Amazon China. It brought close to 950 downloads. Here is part of main screen:

    • 9th and 12th November - Fruit Dating was promoted through AppGratis. AppGratis is app discovery service. Users have it installed in their phones and are offered one free app a day. The promotion was for both Android (9th) and iOS (12th). Total number of downloads exceeded 13000. AppGratis was most effective from all November promotions,
    • 28th November - Fruit Dating was promoted through Appgratuita service. It looks that this service is smaller and focused mainly on Italy. Again, both versions, Android and iOS were promoted with around 680 downloads.
  • we (me and Tomáš Kopecký) started to work on new game - classic match 3. But we moved it into world of flat design. We do not want to compete with other match 3 games with shiny graphical effects. We want to make neat match 3 game with small install size, that will not push players into IAPs. Game has two modes - levels and time attack. Currently we are testing all 150 levels. This is our first game we put Google Analytics into. The events sent from game help us balance levels difficulty. Here is arranged screenshot (used Free iPhone 6, 4.7-inch Template from Dribbble.com):

  • I still continue in work on big Unity project. The progress is slow as I am also still learning Unity as I go. Anyway, I have small but flexible system for moving platforms and other objects. It is combined with flexible events and I already made some applications of this system in the game. I also started writing tutorials on these Unity topics. You can read first three here:
  And here is how result can look - object is following defined path (yellow squares), is performing different kinds of move (linear, quadratic), can wait in path nodes, is emitting event (blue circle) on impact (dust). Other features are described in tutorials.


Report


 Now, to November figures. Here is table for paid apps:


 There is big decrease, compared to October. From $146,9 to $65,1. It is because effect of big promotion events for Shards and Deadly Abyss 2 in September is definitely over.


 Promotion events in November were related mainly to Fruit Dating. For this reason its share increased from 5% to 15%. The most profitable is still Shards.

 In table and chart below are stats for versions supported with ads. I also moved here downloads during promotion events as these downloads were for free. Leaving it in paid table would spoil stats.




 All income channels are more or less the same as in October except for Chartboost. November was the best month with Chartboost during this year (its share raised from 47% to 67%). Thanks to it the overall income remained close to income in October:

   total income for SBC team in November = $65,1 + $220,7 = $285,8 (+ 3,9% compared to October report). It is still far away from my mid term target $750 / month.



Next?


 In December I am continuing work on my projects. I hope we will finish and release our match-3 game. I will also continue with Unity game and currently I have at least one topic I want to write tutorial on (how to keep colliders visible in part of object hierarchy in scene editor when editing single collider)








Monday, December 8, 2014

Unity 2D: Simple system for moving platforms (not only!) - improving events






 Other Unity articles
  Simple system for moving platforms (not only!)
  Traversing GameObjects hierarchy



 In article "Simple system for moving platforms (not only!)" we created simple system that allowed us to move platforms or other objects along path defined with path nodes. This path had visual representation in editor and the system had some parameters that allowed us easy parametrization (waiting in nodes of our choice, setting speed and speed modifiers, moving in ping-pong way, loops or only once, setting movement type like linear, cos, quadratic ...).

 One of the features was ability to send events when platform or any other object following path arrived to destination path node or when leaving current path node. Originally this event was defined like stupid enum - just listing of some generalized event names:

public enum ePathNodeEventType
    {
        Nothing,
        Hit
    }

 In this tutorial we will change this enum to regular event object. The result animated above shows small dust animation when platform is hit. This animation is initiated with event. Each event will have also some parameters as pre-delay and post-delay and also it will have possibility to point to next event. In this way we can initiate chains of events. Here is how our inspector for PathNode will change:


 You can download final source files here. We first change two public variables holding enum values in PathNode.cs to this:

    public PathNodeEvent mOnArriveEvent;
    public PathNodeEvent mOnLeaveEvent;

 This will cause small change in our existing PathFollower class where we have to change OnLeaveEvent and OnArriveEvent like this:

    // -------------------------------------------------------------------------
    public virtual void OnLeaveEvent(PathNodeEvent aEvent)
    {
        if (aEvent != null)
            aEvent.ProcessEvent(gameObject);
    }

    // -------------------------------------------------------------------------
    public virtual void OnArriveEvent(PathNodeEvent aEvent)
    {
        if (aEvent != null)
            aEvent.ProcessEvent(gameObject);
    }

 Now we need to create new class. This class will name PathNodeEvent. Its properties will be delay before event is processed and time after the event is processed. The delay after event may seem unnecessary, but there is one more property - next event (again PathNodeEvent or derived class). The delay after processing current event says how much time to wait before processing next event. The event chain is stopped when next event is null.

 Here is listing of the beginning of PathNodeEvent class:

using UnityEngine;
using System.Collections;

public class PathNodeEvent : MonoBehaviour
{
    public float mDelayBefore = 0.0f;
    public float mDelayAfter = 0.0f;
    public PathNodeEvent mNextEvent = null;

 And here is rest of this small, but powerful class:

    // -------------------------------------------------------------------------
    public virtual void ProcessEvent(GameObject aGameObject)
    {
        StartCoroutine(Process(aGameObject));
    }

    // -------------------------------------------------------------------------
    protected virtual void DoProcess(GameObject aGameObject)
    {
        Debug.Log(gameObject.name + ": processing event");
    }

    // -------------------------------------------------------------------------
    protected IEnumerator Process(GameObject aGameObject)
    {
        if (mDelayBefore > 0)
            yield return new WaitForSeconds(mDelayBefore);

        DoProcess(aGameObject);

        if (mDelayAfter > 0)
            yield return new WaitForSeconds(mDelayAfter);

        if (mNextEvent != null)
            mNextEvent.ProcessEvent(aGameObject);
    }
}

 From the PathFollower class you see that ProcessEvent is called. The method is virtual so we can override it in subclasses. The implementation here is default. What it does is, that coroutine (Process) is started. There is first processed delay before event, then event itself - DoProcess. If some delay after event is entered, it is processed next and finally we check if there is any next event.

 This class does not do anything interesting except it prints message to debug console. Most of the real event will be subclasses of this class. You can override ProcessEvent if you are not interesting in delays or in chaining (for some simple event) or you can override DoProcess and you will have all the features described above.

 So, let's subclass it with simple SpawnEvent. The class is note derived from MonoBehaviour, but from our PathNodeEvent:


using UnityEngine;
using System.Collections;

public class SpawnEvent : PathNodeEvent
{
    public Transform mSpawnPoint;
    public GameObject mSpawnObject;

    // -------------------------------------------------------------------------
    public override void ProcessEvent(GameObject aGameObject)
    {
        // check for undefined spawn object or point
        if (mSpawnObject == null)
        {
            Debug.LogError("Spwan object is not defined");
            return;
        }
        else if (mSpawnPoint == null)
        {
            Debug.LogError("Spawn point is note defined");
            return;
        }

        // all ok, all defined
        /*GameObject spawnObject = (GameObject) */ Instantiate(mSpawnObject,
            mSpawnPoint.position, mSpawnPoint.rotation);
    }
}

 This type of event is very simple, so we override directly ProcessEvent and are not interested in delays. It has two additional public properties - Spawn Point and Spawn Object. Spawn object is "something" that will be spawned at "point". the inspector view looks like this:


 It means, you have to create event object somewhere in the scene. Spawn point can be any other Transform in the scene. SpawnObject can be prefab, which is very useful. To save one one GameObject in scene, the event here has its own Transform as spawn point - it is pointing to itself. Object in scene are arranged like this:


 The yellow squares are PathNodes from previous tutorial. The blue circle is event. The spawn object I am pointing to is short dust animation. When running it. you will get the result already shown in the beginning:


 The event spawns the dust when second PathNode is reached. But you can also play sound in the same event or chain sound event and animation event.

 Download (4 kb) here

 As you can imagine, the original PathFollowing system in connection with events can have lot of usages. I think it can also be used for some character animation scenes. Good thing is that both, the path system and events are easily extensible.