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 = "";
}
}
Subscribe to:
Post Comments (Atom)
Countdoun set up script ( CountdownManager)
using UnityEngine; using TMPro; public class CountdownManager : MonoBehaviour { public TMP_Text countdownText; public GameObject ca...
-
Learn how to become a special person: You want to know how can you also be a special person.There is no need to know or do anything t...
-
how to make money online Making money online can be a viable option if you're willing to put in time, effort, and sometimes ...
No comments:
Post a Comment