unity 3d student

Beginner B23 – Particle Systems

Creating a simple explosion using a particle system instantiated from a prefab.

Code Used (Javascript)

var stars : ParticleEmitter;
  1.  
  2. function OnCollisionEnter (col : Collision) {
  3.  Instantiate(stars, transform.position, transform.rotation);
  4.  Destroy(gameObject);
  5. }

Further Reading

Share via Social Media

  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Add to favorites

11 Comments

    [...] Source: Beginner B23 – Particle Systems (Unity3DStudent.com) [...]

  • [...] Referência: Beginner B23 – Particle Systems (Unity3DStudent.com) [...]

  • Hi,

    I cant seem to get this to work. I get an error explaining
    “UnassignedReferenceException: The variable Explode of ‘WallCollide’ has not been assigned.
    You probably need to assign the Explode variable of the WallCollide script in the inspector.”

    However, I have definitely placed my explosion particle emitter into the script used in the Wall instance…

    var Explode : ParticleEmitter;
    function OnCollisionEnter (collide : Collision) {

    if(collide.gameObject.name == “Shot(Clone)”) {
    Debug.Log(“HIT!”);
    Instantiate(Explode, transform.position, transform.rotation);
    Destroy(gameObject);
    }

    }

    (the Shot(Clone) part is just me being lazy a bit.. never mind that haha)

    So it hits, for sure, but I always get this error, no matter what I do. Ive spent 2 hours trying to fix it.

    • It’s one of 2 things, either you have assigned your particle prefab to the variable slot in the inspector having selected the script in the project panel and forgotten to actually assigned it to the script when it’s attached to your gameobject or prefab object OR it could be a bug in unity – best thing to do about the latter is remove the script as a component of your object or prefab and then reattach it and then reassign the particle prefab to it.

    I just typed up the boxDestroy script. How do I put it onto the object? As itself, it won’t let me save as a script, like the Timed Object Destructor itself. What I’ve done is made another TOD and did Edit Script, and wrote it there. The script works, but now I wonder would the original TOD affect the whole thing to any degree?

    • If you were unable to write a script and attach it to an object then there is either a problem with your unity install or you’re making a mistake..

    As always, great tutorial! Do you think, if you have time of course, you could do a more advanced particle system tutorial, to show how you would make things like clouds, smoke, fire, etc? (Things that would be a little more complex than emitting a bunch of star textures)

  • Really enjoying these tutorials Will. This one was fantastic.

  • [...] サイトの見方がよくわからないですが、 試しにParticleについての章をやってましたが、動画を見れば英語はわからないくて理解できます。 [...]

  • Chuta los locos, aki se habla de too parece kjokj que pesaooh Nice tutorial.

  • This tutorial was one of the funnest so far, always loved playing around with particleFX. Great job WG

Leave a Comment