Home
Index

Using Coroutines in Actions

Using Coroutines in Actions (1.8.1)

Note the coroutine is actually run by the PlayMakerFSM that owns the action.

C# Example:


using UnityEngine;
using System.Collections;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("Test")]
    public class CoroutineTestAction : FsmStateAction
    {
        [RequiredField]
        public FsmFloat time;

        private Coroutine routine;

        public override void Reset()
        {
            time = 5f;
        }

        public override void OnEnter()
        {
            routine = StartCoroutine(DoWait());
        }

        private IEnumerator DoWait()
        {
            yield return new WaitForSeconds(time.Value);

            Log("Finished!");
            Finish();
        }

        public override void OnExit()
        {
            StopCoroutine(routine);
        }
    }
}