Hello everybody,
i am still beginner in Unity so i apologize to advanced programmers with maybe stupid basic question. I am trying to create application in Unity and part of the app is displayed timer (in form of slider) which should move from full (maxValue = 60) to zero. Timer starts after push of the button and it should go down for 60 seconds. I created few Debug logs to track progress of code but I only get to number “3”.
PS. this is my first post here so i really apologize if i write some formatting here wrong.
Thanks for all the help and your suggestions. As you may see english isnt my first language.
here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TimeSlider : MonoBehaviour
{
public Slider slider;
int maxTime = 60;
bool moveSlider = false;
public void Start()
{
Debug.Log("1");
StartCoroutine("countDown");
slider.maxValue = maxTime;
}
private IEnumerator countDown()
{
Debug.Log("2");
while (moveSlider==true)
{
Debug.Log("4");
slider.value = maxTime - 1;
yield return new WaitForSeconds(1f);
if (slider.value < 0)
{
Debug.Log("5");
moveSlider = false;
}
}
}
public void startTimer ()
{
moveSlider = true;
Debug.Log("3");
}
/*
public void resetTimer()
{
moveSlider = false;
slider.maxValue = maxTime;
}
*/
}