Hi here's how I implement the timer
So like the usual, I created 2 Objects, 1 is unity UI which is the UI which contains the timer itself, and the other one is an empty object which contains how I manipulate the timer.
I start/stop the timer using sequence commands.
This sequence is located at the node which contains the question
Code: Select all
SetActive(myTimer, true); //enables the UI
SetEnabled(GameTimer, true, GameTimer); //enables the object which holds the script
This sequence is located at the node which contains the answer
Code: Select all
SetActive(myTimer, false); //same but stops the timer
SetEnabled(GameTimer, false, GameTimer);
This is the script of the timer itself
Code: Select all
using UnityEngine;
using UnityEngine.UI;
using PixelCrushers.DialogueSystem;
using System.Collections;
public class GameTimer : MonoBehaviour {
public static GameTimer Instance;
public Text timerText;
public float timeLeft = 15;
bool isEnabled = true;
GameObject objTimer;
// Use this for initialization
void Start () {
Instance = this;
objTimer = GameObject.Find("myTimer");
objTimer.SetActive(false);
GameTimer gTimer = GameObject.Find("GameTimer").GetComponent<GameTimer>();
gTimer.enabled = false;
}
// Update is called once per frame
void Update () {
timeLeft -= Time.deltaTime;
timerText.text = timeLeft.ToString("f2");
if (timeLeft <= 0)
{
timeLeft = 0;
timerText.text = timeLeft.ToString("f2");
Debug.Log("Timer stopped");
timeLeft = 15;
string message = "Time";
DialogueLua.SetVariable("Response", message);
Debug.Log(DialogueLua.GetVariable("Response").AsString);
DialogueManager.Instance.SendMessage("OnSequencerMessage", "ChooseResponse");
}
}
public void resetTimer()
{
timeLeft = 15;
}
}
I reset the time using a script that is attached on the platforms
Code: Select all
using UnityEngine;
using System.Collections;
public class ResetTimer : MonoBehaviour {
void OnTriggerEnter (Collider other)
{
if (gameObject.name == "ChoiceATrig")
{
GameTimer.Instance.resetTimer(); //this simply references another script which has the method resetTimer() which contains a timeLeft = 15, 15 is the initial time, it just sets it back to 15 on trigger enter
}else if (gameObject.name == "ChoiceBTrig")
{
GameTimer.Instance.resetTimer();
}
else if (gameObject.name == "ChoiceCTrig")
{
GameTimer.Instance.resetTimer();
}
else if (gameObject.name == "ChoiceDTrig")
{
GameTimer.Instance.resetTimer();
}
else if (gameObject.name == "ChoiceTRUETrig")
{
GameTimer.Instance.resetTimer();
}
else if (gameObject.name == "ChoiceFALSETrig")
{
GameTimer.Instance.resetTimer();
}
}
}
So in your question, maybe? If the dialogue system reads the sequence after the None(), I can stop the timer using the sequence above.