Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

ParticleSystem.startLifetimethrew script? :)

Discussion in 'Scripting' started by Rutenis, Jul 2, 2014.

  1. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297
    Hey, so i tried using this, but i get error. So how do i change Particles startLifeTime threw script?

    Code (csharp):
    1.  
    2. IEnumerator FlamesDeath()
    3.     {
    4.         yield return new WaitForSeconds (0.3f);
    5.         ParticleSystem.Particle.lifetime = 2f;
    6.         yield return new WaitForSeconds (0.3f);
    7.         ParticleSystem.Particle.lifetime = 1f;
    8.         yield return new WaitForSeconds (0.2f);
    9.         ParticleSystem.Particle.lifetime = 0.5f;
    10.         yield return new WaitForSeconds (0.1f);
    11.         ParticleSystem.Particle.lifetime = 0.0f;
    12.  
    13.     }[code]
    14.  
    15. -THANKS!:)
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    what error do you get?

    you're also changing lifetime not "startLifeTime" in that code... care to elaborate on what you are trying to achieve?
     
  3. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297

    Ups, i pasted wrong code.

    error: An object reference is required to access non-static member `UnityEngine.ParticleSystem.Particle.lifetime'

    Well, how do i acces the particle system? GetComponent?

    Code:

    Code (csharp):
    1.  
    2. IEnumerator FlamesDeath()
    3.     {
    4.         yield return new WaitForSeconds (0.3f);
    5.         ParticleSystem.startLifetime = 2f;
    6.         yield return new WaitForSeconds (0.3f);
    7.         ParticleSystem.startLifetime = 1f;
    8.         yield return new WaitForSeconds (0.2f);
    9.         ParticleSystem.startLifetime = 0.5f;[code][/I][/B]
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    yes you need to be referencing a specific particle system not the class.

    If this script is being attached to the gameobject with the particle system component I think you could just use lower case p particleSystem (i.e. like transform is the local transform reference)... if that doesn't work you'll need to use getcomponent and grab a reference.
     
  5. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297
    It worked. Thanks:))