Let's say you have a quest to disarm a bomb before it blows up. The quest title is "Disarm Bomb", and it has a quest entry "Time left: MM:SS" where MM:SS is the countdown.
To implement this, in your database define a variable (or a custom field in your quest). This example assumes you've defined a variable named "secondsLeft". The quest entry text will look a little crazy, but it shows some of the power of the [lua(code)] tag:
Code: Select all
Time left: [lua(string.format("{0:0}:{1:00}", math.floor(Variable["secondsLeft"]/60), Variable["secondsLeft"] % 60))]
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class TestTimedQuest : MonoBehaviour
{
void Start()
{
InvokeRepeating("SubtractOneSecond", 1, 1);
}
void SubtractOneSecond()
{
var secondsLeft = DialogueLua.GetVariable("secondsLeft").AsInt;
secondsLeft--;
DialogueLua.SetVariable("secondsLeft", secondsLeft);
DialogueManager.SendUpdateTracker(); // secondsLeft changed, so update quest tracker HUD.
if (secondsLeft <= 0)
{
CancelInvoke();
Debug.Log("BOOM!"); // Do something when timer reaches zero.
}
}
}