- Home /
Stop Script for a second
What i'm wanting to do is have the script that is running stop for a certain amount of seconds. Since I've got a death particle effect for when you die and i want the play to be able to see the particle effect after they die and then about 1 second later it changes to the end game scene. But instead it just changes the scene right away and you can't see the effect.
This is my script:
if (other.tag == "Player")
{
p_tankexplosion.transform.position = transform.position;
p_tankexplosion.gameObject.SetActive(true);
p_tankexplosion.Play();
Application.LoadLevel("CompleteMainScene");
other.gameObject.SetActive(false);
Destroy(gameObject);
}
I understand that you can use the coroutine method but that seems quite inefficient just to do this simple and small thing. I mean if it's the only way i can do it then i will but isn't there a way to stop the script just for a second that would be ideal for this type of thing?
Answer by MakakWasTaken · Nov 03, 2015 at 10:52 PM
You can use the WaitForSeconds as @meat5000 pointet out, the function needs to have the return type: IEnumerator. Your code could be converted to something like this:
//IEnumerator uses the System.Collections; namespace, which by default is included in a c# file created in Unity.
IEnumerator Wait(float sec) {
if (other.tag == "Player")
{
p_tankexplosion.transform.position = transform.position;
p_tankexplosion.gameObject.SetActive(true);
p_tankexplosion.Play();
yield WaitForSeconds(sec);
Application.LoadLevel("CompleteMainScene");
other.gameObject.SetActive(false);
Destroy(gameObject);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612043826im_/https://answers.unity.com/themes/thub/images/avi.jpg)