Browse Source

Fixed Sprite Object click skips writing Say Text #576

master
Christopher 8 years ago
parent
commit
5a487df208
  1. 29
      Assets/Fungus/Scripts/EventHandlers/ObjectClicked.cs

29
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;
/// <summary>
/// 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.
/// </summary>
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
/// <summary>
@ -26,7 +53,7 @@ namespace Fungus
{
if (clickableObject == this.clickableObject)
{
ExecuteBlock();
StartCoroutine(DoExecuteBlock(waitFrames));
}
}

Loading…
Cancel
Save