Hello everyone
The question is simple but it has given me headaches.
I have a countdown timer and I plan to add time according to a given score.
The method I created works fine the first time, but then fails to add time after that, even though debug.log confirms that the value I put as a condition is read.
Here are my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using System;
using UnityEngine.SceneManagement;
public class CountdownTimer : MonoBehaviour {
public delegate void SetTimer(int seconds);
public static SetTimer ModifyPlayTime;
// For our timer we will use just seconds
public int seconds = 90;
public Text timeText;
private void Awake(){
ModifyPlayTime += ChangeTimer;
}
private void Update() {
seconds -= Time.deltaTime;
if (seconds <= 0.0f){
// End the level here.
timeText.text = "Time Over";
timeText.color= Color.white;
}
timeText.text = "" + (int)seconds;
if (this.gameScreen.ScoreNum == (30)) {
Debug.Log ("score 30");
RaiseExtendPlay (60);
}
if (this.gameScreen.ScoreNum == (60)) {
Debug.Log ("score 60");
RaiseExtendPlay (100);
}
}
public void RaiseExtendPlay(int seconds)
{
if (ModifyPlayTime != null)
ModifyPlayTime(seconds);
}
private void ChangeTimer(int seconds){
ModifyPlayTime -= ChangeTimer;
this.seconds += seconds;
}
}
The 60 seconds works fine, but the 100 seconds don´t work. Debug.Log print “60” 59 times on console.
What I m doing wrong?