countdown script in unity
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Timer : MonoBehaviour
{
public int timeLeft = 20;
public Text countdownText;
GameObject timeuptext;
GameObject timeend;
public int timeCountdownPlays;
public AudioClip CountDownSound;
public AudioSource SoundSource;
void Start()
{
timeuptext = GameObject.Find("TimeUp");
timeuptext.SetActive(false);
timeend = GameObject.Find("Timer Text");
StartCoroutine("LoseTime");
SoundSource.clip = CountDownSound;
}
void Update()
{
countdownText.text = ("" + timeLeft);
if (timeLeft <= 0)
{
timeuptext.SetActive(true);
timeend.GetComponent<Text>().enabled = false;
}
if (timeLeft == timeCountdownPlays)
{
SoundSource.Play();
}
}
IEnumerator LoseTime()
{
while (true)
{
yield return new WaitForSeconds(1);
timeLeft--;
}
}
}
Also in C#:
- c# get value of object in enum
- How to execute script in C#
- how to convert iformfile to byte array c#
- c# get date without time
- c# type of generic is string
- message authorization has been denied for this request. fiddler
- how to populate listbox using list<t> c#
- c# read all text from a file
- load information with txt file to uwp c#
- comment envoyer un socket C#
- isGrounded script for copy
- c# read a webpage data
- unity 2d horizontal movement help
- native-googlesignin configuration is null!?
- c# find index element array
- rotatearound unity
- csharp check if env is development
- create expression func c# for use in where clause
- how to set a transform equal to something unity
- csharp attributes as generics constraints
- C# graph api upload file one drive
- cc# sort list with list if ids
- combine two arraylist c#
- c# enum.getvalues