I got an problem with particle system. I’m instantiating one everytime ball hits an brick, and after it’s done it should be removed automaticly, but these just won’t get destroyed.
Script doesnt give out any errors or warnings, but particle system(clone)'s just won’t get destroyed.
Here’s the whole script:
using UnityEngine;
using System.Collections;
public class BrickScript : MonoBehaviour {
static int numBricks = 0;
public int pointValue = 1;
public int currentLvl = 0;
public int hitPoints = 1;
public int powerUpChance = 3;
public Transform particlesPrefab;
public GameObject[] powerUpPrefabs;
public AudioClip[] hitaudio;
// Use this for initialization
void Start () {
numBricks++;
}
// Update is called once per frame
void Update () {
if ( currentLvl == 4) {
Application.LoadLevel("GameOver");
}
}
void OnCollisionEnter ( Collision col ) {
hitPoints--;
if ( hitPoints <= 0 ) {
Die();
}
if (col.gameObject.tag == "Ball")
Debug.Log ("Particles!");
GameObject go = Instantiate(particlesPrefab, transform.position, Quaternion.identity) as GameObject;
Destroy (go, 2.5f);
}
void Die() {
Destroy ( gameObject );
BallScript ball1Script= GameObject.FindGameObjectWithTag ("Ball").GetComponent<BallScript>();
PaddleScript paddleScript= GameObject.Find ("Paddle").GetComponent<PaddleScript>();
paddleScript.AddPoint(pointValue * (int)ball1Script.curspeed);
numBricks--;
Debug.Log (numBricks);
if ( Random.Range(0, powerUpChance) == 0 ) {
Instantiate( powerUpPrefabs[ Random.Range(0, powerUpPrefabs.Length) ] , transform.position, Quaternion.identity );
}
if ( numBricks <= 0 ) {
//Load Next Level
Application.LoadLevel(currentLvl+1);
if(currentLvl == 1){
GJAPIHelper.Trophies.ShowTrophyUnlockNotification (4086);
}
if(currentLvl == 2){
GJAPIHelper.Trophies.ShowTrophyUnlockNotification (4087);
}
}
}
}
And here’s just the part that SHOULD be removing that.
void OnCollisionEnter ( Collision col ) {
hitPoints--;
if ( hitPoints <= 0 ) {
Die();
}
if (col.gameObject.tag == "Ball")
Debug.Log ("Particles!");
GameObject go = Instantiate(particlesPrefab, transform.position, Quaternion.identity) as GameObject;
Destroy (go, 2.5f);
}
Why it isnt getting destroyed?