diff --git a/Assets/Fungus/Scripts/EventHandlers/ObjectClicked.cs b/Assets/Fungus/Scripts/EventHandlers/ObjectClicked.cs
index d3c653ad..a103a1ef 100644
--- a/Assets/Fungus/Scripts/EventHandlers/ObjectClicked.cs
+++ b/Assets/Fungus/Scripts/EventHandlers/ObjectClicked.cs
@@ -2,6 +2,7 @@
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
+using System.Collections;
namespace Fungus
{
@@ -17,6 +18,32 @@ namespace Fungus
[Tooltip("Object that the user can click or tap on")]
[SerializeField] protected Clickable2D clickableObject;
+ [Tooltip("Wait for a number of frames before executing the block.")]
+ [SerializeField] protected int waitFrames = 1;
+
+ ///
+ /// Executing a block on the same frame that the object is clicked can cause
+ /// input problems (e.g. auto completing Say Dialog text). A single frame delay
+ /// fixes the problem.
+ ///
+ protected virtual IEnumerator DoExecuteBlock(int numFrames)
+ {
+ if (numFrames == 0)
+ {
+ ExecuteBlock();
+ yield break;
+ }
+
+ int count = Mathf.Max(waitFrames, 1);
+ while (count > 0)
+ {
+ count--;
+ yield return new WaitForEndOfFrame();
+ }
+
+ ExecuteBlock();
+ }
+
#region Public members
///
@@ -26,7 +53,7 @@ namespace Fungus
{
if (clickableObject == this.clickableObject)
{
- ExecuteBlock();
+ StartCoroutine(DoExecuteBlock(waitFrames));
}
}