Question by
Venatal · Nov 18, 2015 at 02:52 PM ·
c# tutorial
Is there a way to run Destroy(gameObject) after the game has run the previous code?
Is there a way I can run the Destroy(gameObject) after the game has run everything before it? because I always get errors or PlaySound(0); doesn't actually play because the gameObject is destroyed instantly and if I use Destroy(gameObject, 1) it takes too long to destroy it :/
if (collision2D.transform.name == "BlueWall")
{
ScoreSystem scoreSystem = GetComponent<ScoreSystem>();
scoreSystem.IncreaseScore();
PlaySound(0);
Destroy(gameObject);
}
Comment
Answer by Soos621 · Nov 18, 2015 at 08:17 PM
Use an IEnumerator to wait in a while loop for whatever you want to finish
public class DestroyStuff{
public bool hasFinished;
public GameObject desObj;
IEnumerator DestroySounds (){
while (!hasFinished){
yield return null;
}
Destory(desObj);
}
}
Your answer
Follow this Question
Related Questions
AddListener issue C# 0 Answers
Need Help with a match 3 style game 0 Answers
Help me ! Unity Mana !,HELP ME MANA! 0 Answers
3D Space Shooter C# tutorial 1 Answer