How to re-enable multiple components in one script
Hello. I have this script of a countdown for the car game. When GO text is displayed the car controller is reenabled on cars. The problem is it works for only the first object listed ("quagliatta 3(Clone)") a nothing after it. Can somebody please help me to reenable it for other objects too? I am beginner in C sharp. Here is the script:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class countdown : MonoBehaviour { public GameObject CountDown; public AudioSource threesound; public AudioSource twosound; public AudioSource onesound; public AudioSource ready;
private void Start()
{
StartCoroutine(CountRoutine());
}
IEnumerator CountRoutine()
{
yield return new WaitForSeconds(0.5f);
CountDown.GetComponent<Text>().text = "3";
threesound.Play();
CountDown.SetActive(true);
yield return new WaitForSeconds(1f);
CountDown.SetActive(false);
CountDown.GetComponent<Text>().text = "2";
twosound.Play();
CountDown.SetActive(true);
yield return new WaitForSeconds(1f);
CountDown.SetActive(false);
CountDown.GetComponent<Text>().text = "1";
onesound.Play();
CountDown.SetActive(true);
yield return new WaitForSeconds(1f);
CountDown.SetActive(false);
CountDown.GetComponent<Text>().text = "GO";
ready.Play();
CountDown.SetActive(true);
GameObject.Find("quagliatta 3(Clone)").GetComponent<RCC_CarControllerV3>().enabled = true;
GameObject.Find("quagliatta 4(Clone)").GetComponent<RCC_CarControllerV3>().enabled = true;
}
}
Comment