Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

trouble deleting instantiated particle effect

Discussion in 'Scripting' started by smokingbunny, Dec 20, 2014.

  1. smokingbunny

    smokingbunny

    Joined:
    Jul 24, 2014
    Posts:
    98
    hello all,

    so im trying to delete instatiated particle effects. but for some reason, what i have tried is not working at all.
    i can delete my player fine and dandy, which is done after the sound has played. but the particle effect is something that has been unable to delete

    here is a snippet of my code which includes what is being deleted. but im justh a bit stumped that these are not working. im gathering because its in the enemy, but still cant get it to work

    i have looked all over and what i have found has led me to what i have now, but still it does not delete. found some stuff on the unity answers, but thats the exact same.

    Code (csharp):
    1.  
    2. if(Health <= 0){
    3.    AudioSource.PlayClipAtPoint(deathSound, transform.position);
    4.    GameObject effect = Instantiate(explosion, transform.position, Quaternion.identity) as GameObject;
    5.    Destroy(this.gameObject);
    6.    ScoreManager.score += squareHealthScore;
    7.    Destroy(effect,1);
    8. }
    9.  
    thanks
     
  2. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297

    I think you destroy this script and then try to destroy that particle, your script order is wrong.
     
  3. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    Download the free particle stuff off asset store and then look at the script for the GUI for when you click and it changes the animation, look at how they destroy the particle prefab :) this is what I done last night and learnt how to make effects for when my player attacks my enemy using parts of the script from the GUI.
     
  4. smokingbunny

    smokingbunny

    Joined:
    Jul 24, 2014
    Posts:
    98
    @Rutenis
    tried re-ordering it, but no dice. weird

    @Josenifftodd
    ill have a look, though i try to steer clear of the asset store just because i dont want to resort too it for game dev. i like to try and figure things out and build from scratch ;) thats the OCD in me
    ill have a look though, see what i can find

    thanks
     
  5. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    Ahh true man well if you don't want to check them out I've attached the scripted I used to make it so when my player attacks the particle comes up and then goes :) not sure if its what your looking for but might work It's in JS though.


    Code (JavaScript):
    1. public var attackEffects : GameObject;
    2. public var effectObj : GameObject[];
    3.  
    4. function effectOn(){
    5.     if(attackEffects != null)Destroy( attackEffects );
    6.     attackEffects = Instantiate(effectObj[ arrayNo ] );
    7. }
    8.  
     
  6. smokingbunny

    smokingbunny

    Joined:
    Jul 24, 2014
    Posts:
    98
    oooh, wow. ill have a look-see. thank you. it will be easy to convert

    ill still give the asset store a look, just in case ;)

    thanks again
     
    Josenifftodd likes this.
  7. smokingbunny

    smokingbunny

    Joined:
    Jul 24, 2014
    Posts:
    98
    did find a unity team particle system. nice to see what the particles system can do really. did find some code that could come in handy but will look in other avenues that would be less code.
    may go to it, but good to look at and learn

    thanks again guys
     
  8. smokingbunny

    smokingbunny

    Joined:
    Jul 24, 2014
    Posts:
    98
    i did have an idea on this

    AND, wouldnt scripting the particle work? i did try one way and it didnt but that was with using a timed countdown then destroy. but would feel that would work also.

    just a thought