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

How to play a shuriken particle system?

Discussion in 'Scripting' started by Tiles, Jun 26, 2012.

  1. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    I have this code here. With the old particle system i had no problem to play it with the old keywords ParticleEmitter instead ParticleSystem and emit instead play.

    Code (csharp):
    1. var myparticlesystem: ParticleSystem;
    2. var test:boolean=false;
    3.  
    4. function OnCollisionEnter(other: Collision){
    5.         test=true;
    6.         myparticlesystem.play=true;
    7. }
    The particle system is in the variable slot. Test goes to true with a collision. The collision triggers. But the particle system does not play. I get an error instead:

    Code (csharp):
    1. MissingFieldException: Field 'UnityEngine.ParticleSystem.play' not found.
    The reference says that i have to use Play though (by the way, why is the first letter big here? Shouldn`t it be a small letter?)

    http://unity3d.com/support/documentation/ScriptReference/ParticleSystem.Play.html

    What is wrong here?
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Play is a method, not a property or a field.

    Code (csharp):
    1. myparticlesystem.Play();
     
  3. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Ah, no wonder. So the method has changed too, not just the keywords. Many thanks Dantus :)

    I wish this would be mentioned in the manual too ...
     
  4. Tseng

    Tseng

    Joined:
    Nov 29, 2010
    Posts:
    1,217
    Typical case of RTFM: Particle System. The docs already describes all of the methods the class has.

    Edit:
    P.S.

    ParticleAnimator, ParticleEmiter and ParticleRenderer are part of the legacy (old) Particle system.

    ParticleSystem, ParticleSystem.Particle and ParticleSystemRenderer are the new Shuriken Particle classes
     
    Last edited: Jun 27, 2012
  5. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    This was and is always my first way. But this didn`t help me, as usual. I nearly always end in the forum when i have a look at the reference. Because it is more a dictionary. And doesn`t really help with the useage in most cases.

    I was in need of Dantus`s code snippet to understand what is meant. And then i understood it very quick. So again thanks Dantus.
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You can see it in the documentation that you are dealing with a function (method). The line just below the title is:

    I struggle with this kind of things too if I have to implement something in UnityScript, as it doesn't (or maybe didn't?) have such good autocompletion as C#.

    @Tseng: You can not tell someone RTFM, if he even posted a link to it :).
     
  7. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Yes, but i didn`t realize it until i saw your code snippet. I was too focused at the old method with the flag. My brain refused to accept what it has read. Maybe i should have a look for a new brain. Do you have one left? :)