I’ve coded a simple timer in unity using objects.
See this Gyazo:
nieuweversie - GameSceneTwoPlayers - PC, Mac & Linux Standalone - Unity 2020.3.27f1 Personal* (gyazo.com)
Is there a better way to to this, I am feeling I used to much code for this.
public class TimerButton : MonoBehaviour
{
public GameObject ButtonOne;
public GameObject ButtonTwo;
public GameObject ButtonThree;
public GameObject ButtonFour;
public GameObject Questions;
public GameObject Border;
public GameObject PlayerOne;
public GameObject PlayerTwo;
public GameObject HitMe;
public GameObject One;
public GameObject Two;
public GameObject Three;
public AudioSource SourceEndTimer;
public AudioClip ClipEndTimer;
public AudioSource SourceTimerNumber;
public AudioClip ClipTimerNumber;
public void Start()
{
DisableGame();
}
public void ButtonClick()
{
StartCoroutine(ButtonClickStart());
}
IEnumerator ButtonClickStart()
{
HitMe.SetActive(false);
SourceTimerNumber.PlayOneShot(ClipTimerNumber);
Questions.SetActive(true);
yield return new WaitForSeconds(1);
Three.SetActive(false);
SourceTimerNumber.PlayOneShot(ClipTimerNumber);
Two.SetActive(true);
yield return new WaitForSeconds(1);
Two.SetActive(false);
SourceTimerNumber.PlayOneShot(ClipTimerNumber);
One.SetActive(true);
yield return new WaitForSeconds(1);
One.SetActive(false);
EnableGame();
SourceEndTimer.PlayOneShot(ClipEndTimer);
}
void DisableGame()
{
ButtonOne.SetActive(false);
ButtonTwo.SetActive(false);
ButtonThree.SetActive(false);
ButtonFour.SetActive(false);
Questions.SetActive(false);
Border.SetActive(false);
PlayerOne.SetActive(false);
PlayerTwo.SetActive(false);
One.SetActive(false);
Two.SetActive(false);
}
void EnableGame()
{
ButtonOne.SetActive(true);
ButtonTwo.SetActive(true);
ButtonThree.SetActive(true);
ButtonFour.SetActive(true);
Questions.SetActive(true);
Border.SetActive(true);
PlayerOne.SetActive(true);
PlayerTwo.SetActive(true);
}
}