¡Hola! I’m still learning so please bear with me.
i recently watched the live training for state machines link: http://unity3d.com/learn/tutorials/topics/scripting/using-interfaces-make-state-machine-ai
i am trying to modify this code for my own purposes but have come across a stumbling block. i have tried to make a simple countdown time to display using the new UI system but when i play all it displays is the original timeRemaing. for some reason it just doesn’t seem to count down can anyone help? here is my code so far.
public class StatePatternGameplay : MonoBehaviour {
[HideInInspector] public IGameplayState currentState;
[HideInInspector] public CountdownState countdownState;
public Text countdownText;
public float timeRemaining = 5f;
private void Awake()
{
countdownState = new CountdownState (this);
}
void Start ()
{
currentState = countdownState;
}
void Update ()
{
currentState.UpdateState ();
}
and
public class CountdownState : IGameplayState {
private readonly StatePatternGameplay gameplay;
public CountdownState (StatePatternGameplay statePatternGameplay)
{
gameplay = statePatternGameplay;
}
public void UpdateState()
{
gameplay.timeRemaining -= Time.deltaTime;
gameplay.countdownText.text = Mathf.Round (gameplay.timeRemaining).ToString();
}
public void ToCountdownState()
{
Debug.Log ("Can't transition to same state");
}