- Home /
Application.LoadLevel and particle system
Hello,
I've ran into a problem with the particle system. I have an object that when it gets destroyed it explodes and i play a particle system. This works on the first load, but when i restart the level the next time it dies the particle ystem does not activate.
This is the restart :
if (GUI.Button (new Rect (411, 311, 311, 111), "Restart"))
{
Application.LoadLevel("MainGame");
}
And this is the destroy function
using UnityEngine;
using System.Collections;
public class Destroy : MonoBehaviour {
private Timer managerScript;
public ParticleSystem death;
void Start () {
GameObject gameControllerObject = GameObject.FindWithTag("GameController");
managerScript = gameControllerObject.GetComponent <Timer>();
death.Stop();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D other){
Debug.Log(other.gameObject.name);
if (other.gameObject.tag.Equals("Enemy")){
managerScript.showMenu = true;
death.transform.position = gameObject.transform.position;
death.Play();
Destroy(gameObject);
}
}
}
what am i doing wrong?
Nothing? I assume there is a bug with application.load level but i cannot be sure.
Answer by FirstLaw · Apr 02, 2014 at 08:23 AM
I think that when you are destroying your gameobject you are also destroying your particle! and so its not available when you load the level again... is your particle system left active in memory? if so , then i suspect your destroy function is removing the particle.
Also when loading the same level try doing it this way
change Application.LoadLevel("MainGame");
to Application.LoadLevel(Application.loadedLevel);
that may help . then try to see if your particle is getting destroyed and never coming back .... you might want to consider something like Object.DontDestroyOnLoad function to help you keep your particle... if that is the case.. or if anything let the particle disapear or move back to where you have it in memory once you have used it and unlink it from your Gameobject. also consider creating the particle each time the object is spawned ... that might help too
cheers i hope this helps
chaging Application.LoadLevel("$$anonymous$$ainGame"); to Application.LoadLevel(Application.loadedLevel);
seems to have worked. Thanks!
no problem just make sure to pick it as the correct answer! glad to have helped