Sunday, August 10, 2025

Countdoun set up script ( CountdownManager)

using UnityEngine; using TMPro; public class CountdownManager : MonoBehaviour { public TMP_Text countdownText; public GameObject car; public float countdownTime = 3f; private float currentTime; void Start() { // Start me drive disable car.GetComponent().canDrive = false; currentTime = countdownTime; StartCoroutine(CountdownCoroutine()); } System.Collections.IEnumerator CountdownCoroutine() { while (currentTime > 0f) { countdownText.text = Mathf.CeilToInt(currentTime).ToString(); yield return new WaitForSeconds(2f); currentTime -= 1f; } countdownText.text = "OG"; car.GetComponent().canDrive = true; // Ab chalne do yield return new WaitForSeconds(1f); countdownText.text = ""; } } finnal countdown manager script using UnityEngine; using TMPro; public class CountdownManager : MonoBehaviour { public TMP_Text countdownText; public GameObject car; public float countdownTime = 3f; public AudioSource audioSource; // AudioSource component public AudioClip beepSound; // Beep sound clip (1,2,3 ...) public AudioClip goSound; // GO sound clip private float currentTime; void Start() { car.GetComponent().canDrive = false; currentTime = countdownTime; StartCoroutine(CountdownCoroutine()); } System.Collections.IEnumerator CountdownCoroutine() { while (currentTime > 0f) { countdownText.text = Mathf.CeilToInt(currentTime).ToString(); // Beep sound play karo if (audioSource != null && beepSound != null) audioSource.PlayOneShot(beepSound); yield return new WaitForSeconds(1f); currentTime -= 1f; } countdownText.text = "GO!"; // GO sound play karo if (audioSource != null && goSound != null) audioSource.PlayOneShot(goSound); yield return new WaitForSeconds(2f); car.GetComponent().canDrive = true; countdownText.text = ""; } } countdown sound ke sath final script using UnityEngine; using TMPro; public class CountdownManager : MonoBehaviour { public TMP_Text countdownText; public GameObject car; public float countdownTime = 3f; public AudioSource audioSource; // AudioSource component public AudioClip beepSound; // Beep sound clip (1,2,3 ...) public AudioClip goSound; // GO sound clip private float currentTime; void Start() { car.GetComponent().canDrive = false; currentTime = countdownTime; StartCoroutine(CountdownCoroutine()); } System.Collections.IEnumerator CountdownCoroutine() { while (currentTime > 0f) { countdownText.text = Mathf.CeilToInt(currentTime).ToString(); // Beep sound play karo if (audioSource != null && beepSound != null) audioSource.PlayOneShot(beepSound); yield return new WaitForSeconds(1f); currentTime -= 1f; } countdownText.text = "GO!"; // GO sound play karo if (audioSource != null && goSound != null) audioSource.PlayOneShot(goSound); yield return new WaitForSeconds(2f); car.GetComponent().canDrive = true; countdownText.text = ""; } }

No comments:

Post a Comment

Countdoun set up script ( CountdownManager)

using UnityEngine; using TMPro; public class CountdownManager : MonoBehaviour { public TMP_Text countdownText; public GameObject ca...