I want to make it so that when a key is pressed a variable starts counting down from 10 to 0.
C# or Java Script is fine.
(I looked in other questions similar to this, but couldn’t find what I was looking for.)
float countdownValue=10;
float countdown;
public Ienumerator StartCountdown()
{
countdown = countdownValue;
while (countdown >0)
{
yield return new WaitForSeconds(1.0f);
countdown --;
}
}
StartCoroutine(StartCountdown());
for (int i = 10; i >= 0; i–)
{
}
In the end, this is what worked. C#:
if (Input.GetKeyDown("a"))
{
countdown();
StartCoroutine(countdown());
}
IEnumerator countdown()
{
yield return new WaitForSeconds(10.0f);
Debug.Log ("It's been 10 seconds!");
}